From ce6ff58da279f3d6614cd402756e7cf8e7095ef1 Mon Sep 17 00:00:00 2001 From: Ben Ratzlaff Date: Mon, 9 Apr 2018 23:04:08 -0700 Subject: [PATCH] Add tests for xcode id generator --- modules/xcode/tests/test_xcode4_project.lua | 47 +++++++++++++++++++++ src/host/os_uuid.c | 2 +- src/host/premake.h | 3 +- src/host/string_hash.c | 4 +- 4 files changed, 52 insertions(+), 4 deletions(-) diff --git a/modules/xcode/tests/test_xcode4_project.lua b/modules/xcode/tests/test_xcode4_project.lua index 813b6b8b..ae308b07 100644 --- a/modules/xcode/tests/test_xcode4_project.lua +++ b/modules/xcode/tests/test_xcode4_project.lua @@ -18,6 +18,7 @@ xcode.used_ids = {} + local old_idfn = xcode.newid xcode.newid = function(node, usage) local name = node if usage then @@ -63,6 +64,52 @@ tr = xcode.buildprjtree(prj) end +--------------------------------------------------------------------------- +-- xcode id generation tests +--------------------------------------------------------------------------- + + local function print_id(...) + _p("%s - %s", xcode.newid(...), old_idfn(...)) + end + + function suite.IDGeneratorIsDeterministic() + print_id("project", "Debug") + print_id("project", "Release") + test.capture [[ +[project:Debug] - B266956655B21E987082EBA6 +[project:Release] - DAC961207F1BFED291544760 + ]] + end + + function suite.IDGeneratorIsDifferent() + print_id("project", "Debug", "file") + print_id("project", "Debug", "hello") + test.capture [[ +[project:Debug] - 47C6E72E5ED982604EF57D6E +[project:Debug(2)] - 8DCA12C2873014347ACB7102 + ]] + end + + function suite.IDGeneratorSame3() + print_id("project", "Release", "file") + print_id("project", "Release", "file") + print_id("project", "Release", "file") + test.capture [[ +[project:Release] - 022ECCE82854FC9A8F5BF328 +[project:Release(2)] - 022ECCE82854FC9A8F5BF328 +[project:Release(3)] - 022ECCE82854FC9A8F5BF328 + ]] + end + + function suite.IDGeneratorMoreThanNecessary() + print_id("a", "b", "c", "d", "e", "f") + print_id("abcdef") + test.capture [[ +[a:b] - 63AEF3DD89D5238FF0DC1A1D +[abcdef] - 9F1AF6957CC5F947506A7CD5 + ]] + end + --------------------------------------------------------------------------- -- XCBuildConfiguration_Project tests --------------------------------------------------------------------------- diff --git a/src/host/os_uuid.c b/src/host/os_uuid.c index 6e9d5e87..57cd6572 100644 --- a/src/host/os_uuid.c +++ b/src/host/os_uuid.c @@ -16,7 +16,7 @@ * without the help of the determinately sized C99 data types that * are not yet universally supported. */ -static void add(unsigned char* bytes, int offset, unsigned long value) +static void add(unsigned char* bytes, int offset, uint32_t value) { int i; for (i = 0; i < 4; ++i) diff --git a/src/host/premake.h b/src/host/premake.h index d26e4ef4..b31ae73d 100644 --- a/src/host/premake.h +++ b/src/host/premake.h @@ -53,6 +53,7 @@ #else #include #endif +#include /* not all platforms define this */ #ifndef FALSE @@ -85,7 +86,7 @@ extern const char* scripts_path; /* Bootstrapping helper functions */ int do_chdir(lua_State* L, const char* path); -unsigned long do_hash(const char* str, int seed); +uint32_t do_hash(const char* str, int seed); void do_getabsolute(char* result, const char* value, const char* relative_to); int do_getcwd(char* buffer, size_t size); int do_isabsolute(const char* path); diff --git a/src/host/string_hash.c b/src/host/string_hash.c index 80fb8182..51e59ea2 100644 --- a/src/host/string_hash.c +++ b/src/host/string_hash.c @@ -17,11 +17,11 @@ int string_hash(lua_State* L) } -unsigned long do_hash(const char* str, int seed) +uint32_t do_hash(const char* str, int seed) { /* DJB2 hashing; see http://www.cse.yorku.ca/~oz/hash.html */ - unsigned long hash = 5381; + uint32_t hash = 5381; if (seed != 0) { hash = hash * 33 + seed;