diff options
Diffstat (limited to 'tests/projects/other/bin2obj')
| -rw-r--r-- | tests/projects/other/bin2obj/src/asset2.bin | 1 | ||||
| -rw-r--r-- | tests/projects/other/bin2obj/src/main.c | 19 | ||||
| -rw-r--r-- | tests/projects/other/bin2obj/transform.lua | 5 | ||||
| -rw-r--r-- | tests/projects/other/bin2obj/xmake.lua | 2 |
4 files changed, 26 insertions, 1 deletions
diff --git a/tests/projects/other/bin2obj/src/asset2.bin b/tests/projects/other/bin2obj/src/asset2.bin new file mode 100644 index 000000000..d7ffc4b96 --- /dev/null +++ b/tests/projects/other/bin2obj/src/asset2.bin @@ -0,0 +1 @@ +hello luafile!
\ No newline at end of file diff --git a/tests/projects/other/bin2obj/src/main.c b/tests/projects/other/bin2obj/src/main.c index bf2a8a1d8..03c50352d 100644 --- a/tests/projects/other/bin2obj/src/main.c +++ b/tests/projects/other/bin2obj/src/main.c @@ -12,6 +12,12 @@ extern const uint8_t _binary_xmake_ico_end[]; extern const uint8_t _binary_asset_bin_start[]; extern const uint8_t _binary_asset_bin_end[]; +extern const uint8_t _binary_asset2_bin_start[]; +extern const uint8_t _binary_asset2_bin_end[]; + +extern const uint8_t _binary_asset2_bin_start[]; +extern const uint8_t _binary_asset2_bin_end[]; + static void hexdump(const char* name, const uint8_t* data, uint32_t size) { printf("%s: size: %u bytes\n", name, (unsigned int)size); if (size == 0) { @@ -95,19 +101,30 @@ int main(int argc, char** argv) { const uint32_t _binary_data_bin_size = (uint32_t)(_binary_data_bin_end - _binary_data_bin_start); const uint32_t _binary_xmake_ico_size = (uint32_t)(_binary_xmake_ico_end - _binary_xmake_ico_start); const uint32_t _binary_asset_bin_size = (uint32_t)(_binary_asset_bin_end - _binary_asset_bin_start); + const uint32_t _binary_asset2_bin_size = (uint32_t)(_binary_asset2_bin_end - _binary_asset2_bin_start); hexdump("data.bin", _binary_data_bin_start, _binary_data_bin_size); printf("\n"); hexdump("xmake.ico", _binary_xmake_ico_start, _binary_xmake_ico_size); printf("\n"); hexdump("asset.bin (transformed)", _binary_asset_bin_start, _binary_asset_bin_size); + printf("\n"); + hexdump("asset2.bin (transformed by lua file)", _binary_asset2_bin_start, _binary_asset2_bin_size); - // verify the transform: asset.bin must be the reverse of "hello transform!" (+ zeroend '\0') + // verify the function transform: asset.bin must be the reverse of "hello transform!" (+ zeroend '\0') const char* expected = "!mrofsnart olleh"; if (_binary_asset_bin_size != 17 || memcmp(_binary_asset_bin_start, expected, 16) != 0) { printf("asset.bin: transform verification failed!\n"); return 1; } printf("asset.bin: transform verification ok\n"); + + // verify the lua-file transform: asset2.bin must be the reverse of "hello luafile!" (+ zeroend '\0') + const char* expected2 = "!elifaul olleh"; + if (_binary_asset2_bin_size != 15 || memcmp(_binary_asset2_bin_start, expected2, 14) != 0) { + printf("asset2.bin: transform verification failed!\n"); + return 1; + } + printf("asset2.bin: transform verification ok\n"); return 0; } diff --git a/tests/projects/other/bin2obj/transform.lua b/tests/projects/other/bin2obj/transform.lua new file mode 100644 index 000000000..54cf1f394 --- /dev/null +++ b/tests/projects/other/bin2obj/transform.lua @@ -0,0 +1,5 @@ +function main(inputfile, outputfile) + import("core.base.bytes") + local data = io.readfile(inputfile, {encoding = "binary"}) + io.writefile(outputfile, data:reverse(), {encoding = "binary"}) +end diff --git a/tests/projects/other/bin2obj/xmake.lua b/tests/projects/other/bin2obj/xmake.lua index 0cf4fb4fc..d383bb1bb 100644 --- a/tests/projects/other/bin2obj/xmake.lua +++ b/tests/projects/other/bin2obj/xmake.lua @@ -12,3 +12,5 @@ target("test") local data = io.readfile(inputfile, {encoding = "binary"}) io.writefile(outputfile, data:reverse(), {encoding = "binary"}) end}) + -- transform can also be a lua script file (supported by the project generators) + add_files("src/asset2.bin", {zeroend = true, transform = path.join(os.projectdir(), "transform.lua")}) |
