diff options
| author | ruki <[email protected]> | 2026-07-17 23:54:18 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2026-07-17 23:54:18 +0800 |
| commit | 4d7c731fb5029204f1a557acccbcb6fb4d961f3b (patch) | |
| tree | 38d4a663a705d3532360e0a046ffd8d77d583cb2 | |
| parent | f467d71abc40d4fee6e896d7a0b8e4f5be7e16db (diff) | |
improve bin2c tests
| -rw-r--r-- | tests/projects/other/bin2c/src/asset.bin | 1 | ||||
| -rw-r--r-- | tests/projects/other/bin2c/src/main.c | 15 | ||||
| -rw-r--r-- | tests/projects/other/bin2c/test.lua | 2 | ||||
| -rw-r--r-- | tests/projects/other/bin2c/xmake.lua | 8 |
4 files changed, 25 insertions, 1 deletions
diff --git a/tests/projects/other/bin2c/src/asset.bin b/tests/projects/other/bin2c/src/asset.bin new file mode 100644 index 000000000..0c8cc9a8c --- /dev/null +++ b/tests/projects/other/bin2c/src/asset.bin @@ -0,0 +1 @@ +hello transform! diff --git a/tests/projects/other/bin2c/src/main.c b/tests/projects/other/bin2c/src/main.c index 74898132c..3c8bcc60b 100644 --- a/tests/projects/other/bin2c/src/main.c +++ b/tests/projects/other/bin2c/src/main.c @@ -1,6 +1,7 @@ #include <stdio.h> #include <stdint.h> #include <ctype.h> +#include <string.h> static unsigned char g_bin_data[] = { #include "data.bin.h" @@ -10,6 +11,10 @@ static unsigned char g_ico_data[] = { #include "xmake.ico.h" }; +static unsigned char g_asset_data[] = { + #include "asset.bin.h" +}; + 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) { @@ -94,5 +99,15 @@ int main(int argc, char** argv) hexdump("data.bin", g_bin_data, (uint32_t)sizeof(g_bin_data)); printf("\n"); hexdump("xmake.ico", g_ico_data, (uint32_t)sizeof(g_ico_data)); + printf("\n"); + hexdump("asset.bin (transformed)", g_asset_data, (uint32_t)sizeof(g_asset_data)); + + // verify the transform: asset.bin must be the reverse of "hello transform!\n" (+ zeroend '\0') + const char* expected = "\n!mrofsnart olleh"; + if (sizeof(g_asset_data) != 18 || memcmp(g_asset_data, expected, 17) != 0) { + printf("asset.bin: transform verification failed!\n"); + return 1; + } + printf("asset.bin: transform verification ok\n"); return 0; } diff --git a/tests/projects/other/bin2c/test.lua b/tests/projects/other/bin2c/test.lua index b57362078..a23bb98a3 100644 --- a/tests/projects/other/bin2c/test.lua +++ b/tests/projects/other/bin2c/test.lua @@ -1,3 +1,5 @@ function main(t) t:build() + -- run the target, main.c verifies the transformed asset.bin and exits non-zero on mismatch + os.exec("xmake run test") end diff --git a/tests/projects/other/bin2c/xmake.lua b/tests/projects/other/bin2c/xmake.lua index b00dedb65..f37aa1218 100644 --- a/tests/projects/other/bin2c/xmake.lua +++ b/tests/projects/other/bin2c/xmake.lua @@ -4,7 +4,13 @@ target("test") set_kind("binary") add_rules("utils.bin2c", {linewidth = 16, extensions = {".bin", ".ico"}}) add_files("src/*.c") - add_files("src/*.bin") + add_files("src/data.bin") add_files("src/xmake.ico", {nozeroend = true}) + add_files("src/asset.bin", {transform = function (inputfile, outputfile, opt) + import("core.base.bytes") + assert(bytes and opt.target) + local data = io.readfile(inputfile, {encoding = "binary"}) + io.writefile(outputfile, data:reverse(), {encoding = "binary"}) + end}) |
