working on moving the 'TestCompression' code into its own crate
This commit is contained in:
parent
21f6e492f6
commit
c022b15465
@ -3,7 +3,3 @@ coverage = "tarpaulin --out Html --skip-clean --output-dir coverage"
|
|||||||
|
|
||||||
[build]
|
[build]
|
||||||
rustc-wrapper = "sccache"
|
rustc-wrapper = "sccache"
|
||||||
|
|
||||||
[target.x86_64-unknown-linux-gnu]
|
|
||||||
linker = "clang"
|
|
||||||
rustflags = ["-C", "link-arg=-fuse-ld=/usr/local/bin/mold"]
|
|
||||||
|
|||||||
97
.idea/workspace.xml
generated
97
.idea/workspace.xml
generated
@ -8,31 +8,19 @@
|
|||||||
</component>
|
</component>
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="8fa1ca42-220d-4157-8efb-e642e4673d11" name="Changes" comment="">
|
<list default="true" id="8fa1ca42-220d-4157-8efb-e642e4673d11" name="Changes" comment="">
|
||||||
<change afterPath="$PROJECT_DIR$/gemma/tests/computer_manager.rs" afterDir="false" />
|
<change afterPath="$PROJECT_DIR$/gemma/src/test_compression.rs" afterDir="false" />
|
||||||
<change afterPath="$PROJECT_DIR$/gemma/tests/delay_timer.rs" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.cargo/config.toml" beforeDir="false" afterPath="$PROJECT_DIR$/.cargo/config.toml" afterDir="false" />
|
||||||
<change afterPath="$PROJECT_DIR$/gemma/tests/instructions.rs" afterDir="false" />
|
|
||||||
<change afterPath="$PROJECT_DIR$/gemma/tests/keypad.rs" afterDir="false" />
|
|
||||||
<change afterPath="$PROJECT_DIR$/gemma/tests/registers.rs" afterDir="false" />
|
|
||||||
<change afterPath="$PROJECT_DIR$/gemma/tests/sound_timer.rs" afterDir="false" />
|
|
||||||
<change afterPath="$PROJECT_DIR$/gemma/tests/stack.rs" afterDir="false" />
|
|
||||||
<change afterPath="$PROJECT_DIR$/gemma/tests/system_memory.rs" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/gemma/src/chip8/computer.rs" beforeDir="false" afterPath="$PROJECT_DIR$/gemma/src/chip8/computer.rs" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/Cargo.lock" beforeDir="false" afterPath="$PROJECT_DIR$/Cargo.lock" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/gemma/src/chip8/instructions.rs" beforeDir="false" afterPath="$PROJECT_DIR$/gemma/src/chip8/instructions.rs" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/Cargo.toml" beforeDir="false" afterPath="$PROJECT_DIR$/Cargo.toml" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/gemma/src/chip8/keypad.rs" beforeDir="false" afterPath="$PROJECT_DIR$/gemma/src/chip8/keypad.rs" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/coverage/tarpaulin-report.html" beforeDir="false" afterPath="$PROJECT_DIR$/coverage/tarpaulin-report.html" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/gemma/src/chip8/util.rs" beforeDir="false" afterPath="$PROJECT_DIR$/gemma/src/chip8/util.rs" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/gemma/Cargo.toml" beforeDir="false" afterPath="$PROJECT_DIR$/gemma/Cargo.toml" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/gemma/src/bin/testcompression.rs" beforeDir="false" afterPath="$PROJECT_DIR$/gemma/src/bin/testcompression.rs" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/gemma/src/lib.rs" beforeDir="false" afterPath="$PROJECT_DIR$/gemma/src/lib.rs" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/gemma/tests/computer_tests.rs" beforeDir="false" afterPath="$PROJECT_DIR$/gemma/tests/computer_tests.rs" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/gemma/tests/computer_tests.rs" beforeDir="false" afterPath="$PROJECT_DIR$/gemma/tests/computer_tests.rs" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/gemma/tests/state_tests.rs" beforeDir="false" afterPath="$PROJECT_DIR$/gemma/tests/state_tests.rs" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/gemma/tests/keypad.rs" beforeDir="false" afterPath="$PROJECT_DIR$/gemma/tests/keypad.rs" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/gemma/tests/test_compression_tests.rs" beforeDir="false" afterPath="$PROJECT_DIR$/gemma/tests/test_compression_tests.rs" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/gemma/tests/test_utils.rs" beforeDir="false" afterPath="$PROJECT_DIR$/gemma/tests/test_utils.rs" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/gemma/tests/test_utils.rs" beforeDir="false" afterPath="$PROJECT_DIR$/gemma/tests/test_utils.rs" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/gemma/tests/unit_tests.rs" beforeDir="false" afterPath="$PROJECT_DIR$/gemma/tests/unit_tests.rs" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/gemma/tests/util_tests.rs" beforeDir="false" afterPath="$PROJECT_DIR$/gemma/tests/util.rs" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/gemmatelnet/src/telnet_utils.rs" beforeDir="false" afterPath="$PROJECT_DIR$/gemmatelnet/src/telnet_utils.rs" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/gemmautil/src/bin/bin2hex.rs" beforeDir="false" afterPath="$PROJECT_DIR$/gemmautil/src/bin/bin2hex.rs" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/gemmautil/src/bin/ch8asm.rs" beforeDir="false" afterPath="$PROJECT_DIR$/gemmautil/src/bin/ch8asm.rs" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/resources/test/state/smoke_001_round_trip_serialize_deserialize.json" beforeDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/resources/test/state/smoke_002_round_trip_serialize_deserialize_compressed.tflt" beforeDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/resources/test/state/smoke_002_round_trip_serialize_deserialize_compressed.tflt.uncompressed" beforeDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/resources/test/state/video_lowres_schip_draw_chip8_sprite_result.json" beforeDir="false" />
|
|
||||||
</list>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
@ -52,9 +40,9 @@
|
|||||||
<component name="MacroExpansionManager">
|
<component name="MacroExpansionManager">
|
||||||
<option name="directoryName" value="q85ybjmm" />
|
<option name="directoryName" value="q85ybjmm" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectColorInfo"><![CDATA[{
|
<component name="ProjectColorInfo">{
|
||||||
"associatedIndex": 5
|
"associatedIndex": 5
|
||||||
}]]></component>
|
}</component>
|
||||||
<component name="ProjectId" id="2xpB7kQEFEwMZf3OlpLuqA97yi7" />
|
<component name="ProjectId" id="2xpB7kQEFEwMZf3OlpLuqA97yi7" />
|
||||||
<component name="ProjectViewState">
|
<component name="ProjectViewState">
|
||||||
<option name="hideEmptyMiddlePackages" value="true" />
|
<option name="hideEmptyMiddlePackages" value="true" />
|
||||||
@ -62,7 +50,10 @@
|
|||||||
</component>
|
</component>
|
||||||
<component name="PropertiesComponent"><![CDATA[{
|
<component name="PropertiesComponent"><![CDATA[{
|
||||||
"keyToString": {
|
"keyToString": {
|
||||||
|
"Cargo.Build `Test compress_file_to_array`.executor": "Run",
|
||||||
|
"Cargo.Test compress_file_to_array.executor": "Debug",
|
||||||
"Cargo.Test keypad.executor": "Debug",
|
"Cargo.Test keypad.executor": "Debug",
|
||||||
|
"Cargo.Test state_to_json.executor": "Debug",
|
||||||
"Cargo.Test video_lowres_schip_draw_chip8_sprite.executor": "Debug",
|
"Cargo.Test video_lowres_schip_draw_chip8_sprite.executor": "Debug",
|
||||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||||
"RunOnceActivity.rust.reset.selective.auto.import": "true",
|
"RunOnceActivity.rust.reset.selective.auto.import": "true",
|
||||||
@ -72,10 +63,16 @@
|
|||||||
"node.js.selected.package.eslint": "(autodetect)",
|
"node.js.selected.package.eslint": "(autodetect)",
|
||||||
"nodejs_package_manager_path": "npm",
|
"nodejs_package_manager_path": "npm",
|
||||||
"org.rust.cargo.project.model.PROJECT_DISCOVERY": "true",
|
"org.rust.cargo.project.model.PROJECT_DISCOVERY": "true",
|
||||||
|
"org.rust.cargo.project.model.impl.CargoExternalSystemProjectAware.subscribe.first.balloon": "",
|
||||||
"org.rust.first.attach.projects": "true"
|
"org.rust.first.attach.projects": "true"
|
||||||
|
},
|
||||||
|
"keyToStringList": {
|
||||||
|
"com.intellij.ide.scratch.ScratchImplUtil$2/New Scratch File": [
|
||||||
|
"Rust"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}]]></component>
|
}]]></component>
|
||||||
<component name="RunManager" selected="Cargo.Test keypad">
|
<component name="RunManager" selected="Cargo.Test compress_file_to_array">
|
||||||
<configuration name="Run bin2hex" type="CargoCommandRunConfiguration" factoryName="Cargo Command">
|
<configuration name="Run bin2hex" type="CargoCommandRunConfiguration" factoryName="Cargo Command">
|
||||||
<option name="command" value="run --package gemmautil --bin bin2hex" />
|
<option name="command" value="run --package gemmautil --bin bin2hex" />
|
||||||
<option name="workingDirectory" value="file://$PROJECT_DIR$" />
|
<option name="workingDirectory" value="file://$PROJECT_DIR$" />
|
||||||
@ -178,6 +175,23 @@
|
|||||||
<option name="CARGO.BUILD_TASK_PROVIDER" enabled="true" />
|
<option name="CARGO.BUILD_TASK_PROVIDER" enabled="true" />
|
||||||
</method>
|
</method>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
<configuration name="Test compress_file_to_array" type="CargoCommandRunConfiguration" factoryName="Cargo Command" temporary="true">
|
||||||
|
<option name="command" value="test --package gemma --test test_compression_tests compress_file_to_array -- --exact" />
|
||||||
|
<option name="workingDirectory" value="file://$PROJECT_DIR$" />
|
||||||
|
<envs />
|
||||||
|
<option name="emulateTerminal" value="true" />
|
||||||
|
<option name="channel" value="DEFAULT" />
|
||||||
|
<option name="requiredFeatures" value="true" />
|
||||||
|
<option name="allFeatures" value="false" />
|
||||||
|
<option name="withSudo" value="false" />
|
||||||
|
<option name="buildTarget" value="REMOTE" />
|
||||||
|
<option name="backtrace" value="SHORT" />
|
||||||
|
<option name="isRedirectInput" value="false" />
|
||||||
|
<option name="redirectInputPath" value="" />
|
||||||
|
<method v="2">
|
||||||
|
<option name="CARGO.BUILD_TASK_PROVIDER" enabled="true" />
|
||||||
|
</method>
|
||||||
|
</configuration>
|
||||||
<configuration name="Test keypad" type="CargoCommandRunConfiguration" factoryName="Cargo Command" temporary="true">
|
<configuration name="Test keypad" type="CargoCommandRunConfiguration" factoryName="Cargo Command" temporary="true">
|
||||||
<option name="command" value="test --package gemma --test keypad" />
|
<option name="command" value="test --package gemma --test keypad" />
|
||||||
<option name="workingDirectory" value="file://$PROJECT_DIR$" />
|
<option name="workingDirectory" value="file://$PROJECT_DIR$" />
|
||||||
@ -195,6 +209,23 @@
|
|||||||
<option name="CARGO.BUILD_TASK_PROVIDER" enabled="true" />
|
<option name="CARGO.BUILD_TASK_PROVIDER" enabled="true" />
|
||||||
</method>
|
</method>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
<configuration name="Test state_to_json" type="CargoCommandRunConfiguration" factoryName="Cargo Command" temporary="true">
|
||||||
|
<option name="command" value="test --package gemma --test computer_tests state_to_json -- --exact" />
|
||||||
|
<option name="workingDirectory" value="file://$PROJECT_DIR$" />
|
||||||
|
<envs />
|
||||||
|
<option name="emulateTerminal" value="true" />
|
||||||
|
<option name="channel" value="DEFAULT" />
|
||||||
|
<option name="requiredFeatures" value="true" />
|
||||||
|
<option name="allFeatures" value="false" />
|
||||||
|
<option name="withSudo" value="false" />
|
||||||
|
<option name="buildTarget" value="REMOTE" />
|
||||||
|
<option name="backtrace" value="SHORT" />
|
||||||
|
<option name="isRedirectInput" value="false" />
|
||||||
|
<option name="redirectInputPath" value="" />
|
||||||
|
<method v="2">
|
||||||
|
<option name="CARGO.BUILD_TASK_PROVIDER" enabled="true" />
|
||||||
|
</method>
|
||||||
|
</configuration>
|
||||||
<configuration name="Test trevors_chip8_toy" type="CargoCommandRunConfiguration" factoryName="Cargo Command">
|
<configuration name="Test trevors_chip8_toy" type="CargoCommandRunConfiguration" factoryName="Cargo Command">
|
||||||
<option name="command" value="test --workspace" />
|
<option name="command" value="test --workspace" />
|
||||||
<option name="workingDirectory" value="file://$PROJECT_DIR$" />
|
<option name="workingDirectory" value="file://$PROJECT_DIR$" />
|
||||||
@ -231,6 +262,8 @@
|
|||||||
</configuration>
|
</configuration>
|
||||||
<recent_temporary>
|
<recent_temporary>
|
||||||
<list>
|
<list>
|
||||||
|
<item itemvalue="Cargo.Test compress_file_to_array" />
|
||||||
|
<item itemvalue="Cargo.Test state_to_json" />
|
||||||
<item itemvalue="Cargo.Test keypad" />
|
<item itemvalue="Cargo.Test keypad" />
|
||||||
<item itemvalue="Cargo.Test video_lowres_schip_draw_chip8_sprite" />
|
<item itemvalue="Cargo.Test video_lowres_schip_draw_chip8_sprite" />
|
||||||
</list>
|
</list>
|
||||||
@ -248,10 +281,22 @@
|
|||||||
<option name="presentableId" value="Default" />
|
<option name="presentableId" value="Default" />
|
||||||
<updated>1748624969802</updated>
|
<updated>1748624969802</updated>
|
||||||
<workItem from="1748624970827" duration="3451000" />
|
<workItem from="1748624970827" duration="3451000" />
|
||||||
|
<workItem from="1748791611817" duration="1715000" />
|
||||||
</task>
|
</task>
|
||||||
<servers />
|
<servers />
|
||||||
</component>
|
</component>
|
||||||
<component name="TypeScriptGeneratedFilesManager">
|
<component name="TypeScriptGeneratedFilesManager">
|
||||||
<option name="version" value="3" />
|
<option name="version" value="3" />
|
||||||
</component>
|
</component>
|
||||||
|
<component name="XDebuggerManager">
|
||||||
|
<breakpoint-manager>
|
||||||
|
<breakpoints>
|
||||||
|
<line-breakpoint enabled="true" type="com.jetbrains.cidr.execution.debugger.OCBreakpointType">
|
||||||
|
<url>file://$PROJECT_DIR$/gemma/tests/computer_tests.rs</url>
|
||||||
|
<line>149</line>
|
||||||
|
<option name="timeStamp" value="1" />
|
||||||
|
</line-breakpoint>
|
||||||
|
</breakpoints>
|
||||||
|
</breakpoint-manager>
|
||||||
|
</component>
|
||||||
</project>
|
</project>
|
||||||
11
Cargo.lock
generated
11
Cargo.lock
generated
@ -1996,6 +1996,7 @@ dependencies = [
|
|||||||
"dimensioned",
|
"dimensioned",
|
||||||
"flate2",
|
"flate2",
|
||||||
"hex",
|
"hex",
|
||||||
|
"lipsum",
|
||||||
"log",
|
"log",
|
||||||
"pretty_env_logger",
|
"pretty_env_logger",
|
||||||
"rand 0.9.1",
|
"rand 0.9.1",
|
||||||
@ -2906,6 +2907,16 @@ version = "0.9.4"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "cd945864f07fe9f5371a27ad7b52a172b4b499999f1d97574c9fa68373937e12"
|
checksum = "cd945864f07fe9f5371a27ad7b52a172b4b499999f1d97574c9fa68373937e12"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "lipsum"
|
||||||
|
version = "0.9.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "636860251af8963cc40f6b4baadee105f02e21b28131d76eba8e40ce84ab8064"
|
||||||
|
dependencies = [
|
||||||
|
"rand 0.8.5",
|
||||||
|
"rand_chacha 0.3.1",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "litemap"
|
name = "litemap"
|
||||||
version = "0.8.0"
|
version = "0.8.0"
|
||||||
|
|||||||
@ -32,3 +32,4 @@ eframe = { version = "0.29" }
|
|||||||
|
|
||||||
# Testing
|
# Testing
|
||||||
tempfile = "3.20"
|
tempfile = "3.20"
|
||||||
|
lipsum = "0.9"
|
||||||
File diff suppressed because one or more lines are too long
@ -15,4 +15,6 @@ flate2.workspace = true
|
|||||||
clap.workspace = true
|
clap.workspace = true
|
||||||
hex.workspace = true
|
hex.workspace = true
|
||||||
log.workspace = true
|
log.workspace = true
|
||||||
|
# Testing
|
||||||
tempfile.workspace = true
|
tempfile.workspace = true
|
||||||
|
lipsum.workspace = true
|
||||||
|
|||||||
@ -17,7 +17,6 @@
|
|||||||
/// - Uncompressed files must only contain printable ASCII characters
|
/// - Uncompressed files must only contain printable ASCII characters
|
||||||
/// - Stuff I don't know about yet
|
/// - Stuff I don't know about yet
|
||||||
|
|
||||||
|
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use clap::{Parser, Subcommand};
|
use clap::{Parser, Subcommand};
|
||||||
@ -33,6 +32,7 @@ use std::io::prelude::*;
|
|||||||
use std::io;
|
use std::io;
|
||||||
use std::ptr::write;
|
use std::ptr::write;
|
||||||
use log::{debug, info};
|
use log::{debug, info};
|
||||||
|
use gemma::test_compression::TestCompression;
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
#[command(author, version, about = "Compress or decompress a string", long_about = None)]
|
#[command(author, version, about = "Compress or decompress a string", long_about = None)]
|
||||||
@ -56,52 +56,6 @@ enum Commands {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compress_file(input_path: &PathBuf) -> io::Result<()> {
|
|
||||||
let compressed_bytes= compress_file_to_array(input_path);
|
|
||||||
let output_filename = input_path.with_extension("deflated");
|
|
||||||
let mut output_file = File::create(&output_filename)?;
|
|
||||||
output_file.write_all(&compressed_bytes.unwrap())?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn compress_file_to_array(input_path: &Path) -> Result<Vec<u8>, String> {
|
|
||||||
let mut file = File::open(input_path)
|
|
||||||
.map_err(|e| std::io::Error::new(e.kind(), format!("Unable to open input path [{}]: {}", input_path.display(), e)));
|
|
||||||
|
|
||||||
let mut read_buffer = Vec::new();
|
|
||||||
let mut write_buffer = Vec::new();
|
|
||||||
file.unwrap().read_to_end(&mut read_buffer)
|
|
||||||
.map_err(|e| std::io::Error::new(e.kind(), format!("Unable to read input file [{}]: {}", input_path.display(), e)));
|
|
||||||
|
|
||||||
let mut encoder = DeflateEncoder::new(read_buffer, Compression::default());
|
|
||||||
encoder.write_all(&write_buffer)
|
|
||||||
.map_err(|e| std::io::Error::new(e.kind(), format!("Unable to compress data for [{}]: {}", input_path.display(), e)));
|
|
||||||
|
|
||||||
debug!("Compressed file from path: {}", input_path.display());
|
|
||||||
Ok(write_buffer)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn decompress_file_to_array(input_path: &Path) -> Vec<u8> {
|
|
||||||
let file = File::open(input_path)
|
|
||||||
.map_err(|e| std::io::Error::new(e.kind(), format!("Unable to open input path [{}]: {}", input_path.display(), e)));
|
|
||||||
|
|
||||||
let mut decoder = DeflateDecoder::new(file.unwrap());
|
|
||||||
let mut return_vec = Vec::new();
|
|
||||||
decoder.read_to_end(&mut return_vec)
|
|
||||||
.map_err(|e| std::io::Error::new(e.kind(), format!("Unable to decompress data for [{}]: {}", input_path.display(), e)));
|
|
||||||
|
|
||||||
debug!("Decompressed file from path: {}", input_path.display());
|
|
||||||
return_vec
|
|
||||||
}
|
|
||||||
|
|
||||||
fn decompress_file(input_path: &PathBuf) -> io::Result<()> {
|
|
||||||
let decompressed_bytes = decompress_file_to_array(input_path);
|
|
||||||
let output_path = input_path.with_extension("inflated");
|
|
||||||
let mut output_file = File::create(&output_path)?;
|
|
||||||
output_file.write_all(&decompressed_bytes).expect(format!("Unable to write compressed data to [{}]", output_path.display()).as_str());
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
pretty_env_logger::init();
|
pretty_env_logger::init();
|
||||||
|
|
||||||
@ -109,10 +63,10 @@ fn main() {
|
|||||||
|
|
||||||
match cli.command {
|
match cli.command {
|
||||||
Commands::Compress { input } => {
|
Commands::Compress { input } => {
|
||||||
compress_file(&input).expect(format!("Unable to compress {}", input.display()).as_str());
|
TestCompression::compress_file(&input).expect(format!("Unable to compress {}", input.display()).as_str());
|
||||||
}
|
}
|
||||||
Commands::Decompress { input } => {
|
Commands::Decompress { input } => {
|
||||||
decompress_file(&input).expect(format!("Unable to decompress {}", input.display()).as_str());
|
TestCompression::decompress_file(&input).expect(format!("Unable to decompress {}", input.display()).as_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,4 +15,5 @@ pub mod chip8 {
|
|||||||
pub mod quirk_modes;
|
pub mod quirk_modes;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod constants;
|
pub mod constants;
|
||||||
|
pub mod test_compression;
|
||||||
|
|||||||
74
gemma/src/test_compression.rs
Normal file
74
gemma/src/test_compression.rs
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
use std::fs::File;
|
||||||
|
use std::io;
|
||||||
|
use std::io::{Read, Write};
|
||||||
|
use std::path::{Path, PathBuf};
|
||||||
|
use flate2::Compression;
|
||||||
|
use flate2::read::DeflateDecoder;
|
||||||
|
use flate2::write::DeflateEncoder;
|
||||||
|
use log::debug;
|
||||||
|
|
||||||
|
pub struct TestCompression {}
|
||||||
|
|
||||||
|
impl TestCompression {
|
||||||
|
|
||||||
|
pub fn compress_file(input_path: &PathBuf) -> io::Result<()> {
|
||||||
|
let compressed_bytes= TestCompression::compress_file_to_array(input_path);
|
||||||
|
let output_filename = input_path.with_extension("deflated");
|
||||||
|
let mut output_file = File::create(&output_filename)?;
|
||||||
|
output_file.write_all(&compressed_bytes.unwrap())?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn compress_file_to_array(input_path: &Path) -> Result<Vec<u8>, String> {
|
||||||
|
let mut file = File::open(input_path)
|
||||||
|
.map_err(|e| std::io::Error::new(e.kind(), format!("Unable to open input path [{}]: {}", input_path.display(), e)));
|
||||||
|
|
||||||
|
let mut read_buffer = Vec::new();
|
||||||
|
let mut write_buffer = Vec::new();
|
||||||
|
file.unwrap().read_to_end(&mut read_buffer)
|
||||||
|
.map_err(|e| std::io::Error::new(e.kind(), format!("Unable to read input file [{}]: {}", input_path.display(), e)));
|
||||||
|
|
||||||
|
let mut encoder = DeflateEncoder::new(read_buffer, Compression::default());
|
||||||
|
encoder.write_all(&write_buffer)
|
||||||
|
.map_err(|e| std::io::Error::new(e.kind(), format!("Unable to compress data for [{}]: {}", input_path.display(), e)));
|
||||||
|
|
||||||
|
debug!("Compressed file from path: {}", input_path.display());
|
||||||
|
Ok(write_buffer)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn decompress_file_to_array(input_path: &Path) -> Vec<u8> {
|
||||||
|
let file = File::open(input_path)
|
||||||
|
.map_err(|e| std::io::Error::new(e.kind(), format!("Unable to open input path [{}]: {}", input_path.display(), e)));
|
||||||
|
|
||||||
|
let mut decoder = DeflateDecoder::new(file.unwrap());
|
||||||
|
let mut return_vec = Vec::new();
|
||||||
|
decoder.read_to_end(&mut return_vec)
|
||||||
|
.map_err(|e| std::io::Error::new(e.kind(), format!("Unable to decompress data for [{}]: {}", input_path.display(), e)));
|
||||||
|
|
||||||
|
debug!("Decompressed file from path: {}", input_path.display());
|
||||||
|
return_vec
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn decompress_file(input_path: &PathBuf) -> io::Result<()> {
|
||||||
|
let decompressed_bytes = TestCompression::decompress_file_to_array(input_path);
|
||||||
|
let output_path = input_path.with_extension("inflated");
|
||||||
|
let mut output_file = File::create(&output_path)?;
|
||||||
|
output_file.write_all(&decompressed_bytes).expect(format!("Unable to write compressed data to [{}]", output_path.display()).as_str());
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn compress_string(input: &str) -> Vec<u8> {
|
||||||
|
let mut encoder = DeflateEncoder::new(Vec::new(), Compression::default());
|
||||||
|
encoder
|
||||||
|
.write_all(input.as_bytes())
|
||||||
|
.expect("Failed to write data");
|
||||||
|
encoder.finish().expect("Failed to finish compression")
|
||||||
|
}
|
||||||
|
pub fn decompress_to_string(compressed_data: &[u8]) -> Result<String, std::io::Error> {
|
||||||
|
let mut decoder = DeflateDecoder::new(compressed_data);
|
||||||
|
let mut decompressed = String::new();
|
||||||
|
decoder.read_to_string(&mut decompressed)?;
|
||||||
|
Ok(decompressed)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -92,7 +92,7 @@ fn level3_compressed_test() {
|
|||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
x.dump_video_to_string(),
|
x.dump_video_to_string(),
|
||||||
load_compressed_result("gemma_integration.corax_plus")
|
load_compressed_result("gemma_integration_corax_plus")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,7 +132,6 @@ fn level4_test() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn partial_eq_chip8computer() {
|
fn partial_eq_chip8computer() {
|
||||||
let x = Chip8Computer::new();
|
let x = Chip8Computer::new();
|
||||||
@ -140,6 +139,19 @@ fn partial_eq_chip8computer() {
|
|||||||
assert_eq!(x, y)
|
assert_eq!(x, y)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn state_to_json() {
|
||||||
|
let x = Chip8Computer::new();
|
||||||
|
|
||||||
|
let expected = load_compressed_result("gemma_integration_state_to_json1");
|
||||||
|
let actual = x.dump_state_to_json();
|
||||||
|
println!("ACTUAL:: [{}]", actual);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
actual,
|
||||||
|
expected
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn tick_when_not_ready() {}
|
fn tick_when_not_ready() {}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
mod test_utils;
|
mod test_utils;
|
||||||
use gemma::chip8::keypad::Keypad;
|
|
||||||
use crate::test_utils::read_compressed_test_result;
|
use crate::test_utils::read_compressed_test_result;
|
||||||
|
use gemma::chip8::keypad::Keypad;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn keypad_keys_check() {
|
fn keypad_keys_check() {
|
||||||
@ -20,17 +20,12 @@ fn keypad_keys_check() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[ignore]
|
||||||
fn keypad_string_format_test() {
|
fn keypad_string_format_test() {
|
||||||
let k = Keypad::new();
|
|
||||||
|
|
||||||
let expected_result = read_compressed_test_result("gemma_keypad_string_result");
|
let expected_result = read_compressed_test_result("gemma_keypad_string_result");
|
||||||
let actual_result = k.format_as_string();
|
let actual_result = Keypad::new().format_as_string();
|
||||||
|
|
||||||
|
|
||||||
println!("EXPECTING [{}]", expected_result);
|
println!("EXPECTING [{}]", expected_result);
|
||||||
println!("GOT [{}]", actual_result);
|
println!("GOT [{}]", actual_result);
|
||||||
assert_eq!(
|
assert_eq!(actual_result, expected_result);
|
||||||
k.format_as_string(),
|
|
||||||
read_compressed_test_result("gemma_keypad_string_result")
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,7 @@
|
|||||||
use crate::test_utils::{compress_string, decompress_to_string};
|
use std::io::Write;
|
||||||
|
use std::path::Path;
|
||||||
|
use tempfile::{NamedTempFile, tempfile};
|
||||||
|
use gemma::test_compression::TestCompression;
|
||||||
|
|
||||||
mod test_utils;
|
mod test_utils;
|
||||||
|
|
||||||
@ -10,9 +13,42 @@ fn smoke() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn round_trip() {
|
fn round_trip() {
|
||||||
let text_to_process = "The quick brown fox jumps over the lazy dog.";
|
let text_to_process = "The quick brown fox jumps over the lazy dog.";
|
||||||
let compressed = compress_string(text_to_process);
|
let compressed = TestCompression::compress_string(text_to_process);
|
||||||
let decompressed = decompress_to_string(&compressed).unwrap();
|
let decompressed = TestCompression::decompress_to_string(&compressed).unwrap();
|
||||||
|
|
||||||
assert_eq!(text_to_process, decompressed);
|
assert_eq!(text_to_process, decompressed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn compress_file_to_array() {
|
||||||
|
// create a file with plain text...
|
||||||
|
|
||||||
|
// ...compress it to in-memory data
|
||||||
|
|
||||||
|
// ...confirm that matches predefined data
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn compress_file() {
|
||||||
|
// create a file with plain text...
|
||||||
|
|
||||||
|
// ...compress it to a temp file...
|
||||||
|
|
||||||
|
// ...read the compressed data...
|
||||||
|
|
||||||
|
// ...verify it matches initial plain text
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn decompress_file_to_array() {
|
||||||
|
// crate a file with plain text...
|
||||||
|
|
||||||
|
// ...write the compressed version
|
||||||
|
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn decompress_file() {
|
||||||
|
|
||||||
|
}
|
||||||
@ -4,28 +4,16 @@ use flate2::Compression;
|
|||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
use tempfile::tempfile;
|
use tempfile::tempfile;
|
||||||
const TEST_OUTPUT_SAMPLE_DIR: &str = "../resources/test/";
|
use gemma::test_compression::TestCompression;
|
||||||
|
|
||||||
|
const TEST_OUTPUT_SAMPLE_DIR: &str = "../resources/test/";
|
||||||
|
const TEST_ROMS_SAMPLE_DIR: &str = "../resources/roms/";
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn smoke() {
|
fn smoke() {
|
||||||
assert!(true)
|
assert!(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn compress_string(input: &str) -> Vec<u8> {
|
|
||||||
let mut encoder = DeflateEncoder::new(Vec::new(), Compression::default());
|
|
||||||
encoder
|
|
||||||
.write_all(input.as_bytes())
|
|
||||||
.expect("Failed to write data");
|
|
||||||
encoder.finish().expect("Failed to finish compression")
|
|
||||||
}
|
|
||||||
pub fn decompress_to_string(compressed_data: &[u8]) -> Result<String, std::io::Error> {
|
|
||||||
let mut decoder = DeflateDecoder::new(compressed_data);
|
|
||||||
let mut decompressed = String::new();
|
|
||||||
decoder.read_to_string(&mut decompressed)?;
|
|
||||||
Ok(decompressed)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Read a compressed test result and return the expected result
|
/// Read a compressed test result and return the expected result
|
||||||
/// as a string
|
/// as a string
|
||||||
pub fn read_compressed_test_result(suffix: &str) -> String {
|
pub fn read_compressed_test_result(suffix: &str) -> String {
|
||||||
@ -42,7 +30,7 @@ pub fn read_compressed_test_result(suffix: &str) -> String {
|
|||||||
.read_to_end(&mut compressed_data)
|
.read_to_end(&mut compressed_data)
|
||||||
.expect("Unable to compress data");
|
.expect("Unable to compress data");
|
||||||
|
|
||||||
decompress_to_string(&compressed_data).unwrap()
|
TestCompression::decompress_to_string(&compressed_data).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn load_compressed_result(suffix: &str) -> String {
|
pub fn load_compressed_result(suffix: &str) -> String {
|
||||||
@ -50,39 +38,5 @@ pub fn load_compressed_result(suffix: &str) -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn load_rom(to_load: &str) -> Vec<u8> {
|
pub fn load_rom(to_load: &str) -> Vec<u8> {
|
||||||
std::fs::read(format!("../resources/roms/{}.ch8", to_load)).unwrap()
|
std::fs::read(format!("{}{}.ch8", TEST_ROMS_SAMPLE_DIR, to_load)).unwrap()
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn smoke() {
|
|
||||||
assert!(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn compression_round_trip() {
|
|
||||||
let to_compress = "The quick brown fox jumps over the lazy dog.";
|
|
||||||
|
|
||||||
let compressed_text = compress_string(to_compress);
|
|
||||||
let decompressed_text = decompress_to_string(&compressed_text).unwrap();
|
|
||||||
assert_eq!(to_compress, decompressed_text);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn file_compression_round_trip() {
|
|
||||||
// compress string to file...
|
|
||||||
let string_to_compress = "The quick brown fox jumps over the lazy dog.";
|
|
||||||
let compressed_string = compress_string(string_to_compress);
|
|
||||||
let temp_target = tempfile().unwrap();
|
|
||||||
|
|
||||||
//
|
|
||||||
// ...decompress from file...
|
|
||||||
//
|
|
||||||
// ...verify its the same.
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
25
imgui.ini
Normal file
25
imgui.ini
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
[Window][Debug##Default]
|
||||||
|
Pos=60,60
|
||||||
|
Size=400,400
|
||||||
|
Collapsed=0
|
||||||
|
|
||||||
|
[Window][!!!! CONTROLS !!!!]
|
||||||
|
Pos=8,21
|
||||||
|
Size=298,569
|
||||||
|
Collapsed=0
|
||||||
|
|
||||||
|
[Window][Keypad]
|
||||||
|
Pos=1057,32
|
||||||
|
Size=76,99
|
||||||
|
Collapsed=0
|
||||||
|
|
||||||
|
[Window][Video]
|
||||||
|
Pos=321,4
|
||||||
|
Size=800,600
|
||||||
|
Collapsed=0
|
||||||
|
|
||||||
|
[Window][System Memory]
|
||||||
|
Pos=768,2
|
||||||
|
Size=385,600
|
||||||
|
Collapsed=0
|
||||||
|
|
||||||
1
resources/test/gemma_integration_state_to_json1.asc
Normal file
1
resources/test/gemma_integration_state_to_json1.asc
Normal file
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user