summaryrefslogtreecommitdiff
path: root/app/bin/unittest
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2024-11-14 19:35:45 +0100
committerJörg Frings-Fürst <debian@jff-webhosting.net>2024-11-14 19:35:45 +0100
commitdf5520aa2dae5b3ce7abf8733dcdd152898af163 (patch)
tree00d3047bfb14f682bfb5a21010c731ed649bfed7 /app/bin/unittest
parentdf247efec654e512242e4f4f1b0212034f9e01fe (diff)
parentec3c0f6f6e7153fa797dc57a0e95779cbc63a23b (diff)
Merge branch 'release/debian/1_5.3.0GA-1'debian/1_5.3.0GA-1
Diffstat (limited to 'app/bin/unittest')
-rw-r--r--app/bin/unittest/CMakeLists.txt77
-rw-r--r--app/bin/unittest/catalogtest.c63
-rw-r--r--app/bin/unittest/defaultstest.c18
-rw-r--r--app/bin/unittest/dxfformattest.c40
-rw-r--r--app/bin/unittest/pathstest.c56
-rw-r--r--app/bin/unittest/shortentest.c8
-rw-r--r--app/bin/unittest/testfiles/HO-Peco-Code83.xtp6
7 files changed, 173 insertions, 95 deletions
diff --git a/app/bin/unittest/CMakeLists.txt b/app/bin/unittest/CMakeLists.txt
index 7055d0b..ce5f2f4 100644
--- a/app/bin/unittest/CMakeLists.txt
+++ b/app/bin/unittest/CMakeLists.txt
@@ -1,4 +1,7 @@
# build unit tests for the xtrkcad library
+#
+
+# dxf formatting
add_executable(dxfformattest
dxfformattest.c
@@ -11,25 +14,33 @@ target_link_libraries(dxfformattest
add_test(DXFOutputTest dxfformattest)
+# path manipulation
+
add_executable( pathstest
pathstest.c
)
target_link_libraries(pathstest
dynstring
- ${LIBS})
+ xtrkcad-wlib
+ ${LIBS})
add_test(PathsTest pathstest)
+# handling of default settings
+
add_executable( defaultstest
defaultstest.c
)
target_link_libraries(defaultstest
- ${LIBS})
+ xtrkcad-wlib
+ ${LIBS})
add_test(DefaultsTest defaultstest)
+#
+
add_executable(shortentest
shortentest.c
../shortentext.c
@@ -40,24 +51,44 @@ target_link_libraries(shortentest
add_test(ShortenTest shortentest)
-add_test(CatalogTest catalogtest)
-
-set (TESTXTP
- "atl83ho.xtp" "atlasn.xtp" "HO-Peco-Code83.xtp"
- )
-
-foreach(testfile IN LISTS TESTXTP )
- configure_file ( ${CMAKE_CURRENT_SOURCE_DIR}/testfiles/${testfile}
- ${CMAKE_CURRENT_BINARY_DIR}
- COPYONLY )
-endforeach()
-
-add_executable(catalogtest
- catalogtest.c
- ../partcatalog.c
- ../paths.c
- )
-
-target_link_libraries(catalogtest
- dynstring
- ${LIBS}) \ No newline at end of file
+# parts catalog
+# disabled because it pulls in too many dependencies
+
+# add_test(CatalogTest catalogtest)
+
+# # parameter files for test cases:
+# # - two manufacturers
+# # - two scales from same manufacturer
+
+# set (TESTXTP
+# "atl83ho.xtp" "atlasn.xtp" "HO-Peco-Code83.xtp"
+# )
+
+# foreach(testfile IN LISTS TESTXTP )
+# configure_file ( ${CMAKE_CURRENT_SOURCE_DIR}/testfiles/${testfile}
+# ${CMAKE_CURRENT_BINARY_DIR}
+# COPYONLY )
+# endforeach()
+
+# add_executable(catalogtest
+# catalogtest.c
+# ../partcatalog.c
+# ../paths.c
+# ../stringxtc.c
+# ../levenshtein.c
+# )
+
+# target_link_libraries(catalogtest
+# dynstring
+# ${CMOCKA_LIBRARIES}
+# )
+
+
+set_target_properties(
+ dxfformattest
+# catalogtest
+ shortentest
+ defaultstest
+ pathstest
+ PROPERTIES FOLDER UnitTests
+ ) \ No newline at end of file
diff --git a/app/bin/unittest/catalogtest.c b/app/bin/unittest/catalogtest.c
index 6025990..70eeb22 100644
--- a/app/bin/unittest/catalogtest.c
+++ b/app/bin/unittest/catalogtest.c
@@ -10,31 +10,58 @@
#include <setjmp.h>
#include <cmocka.h>
+//#include "../common.h"
#include "../include/partcatalog.h"
-TrackLibrary *trackLib;
-CatalogEntry *catalog;
+ParameterLib *trackLib;
+Catalog *catalog;
+SearchResult* result;
// some dummy functions to suppress linking problems
+const char *
wGetUserHomeDir()
{
+ return("");
+}
+
+void wPrefSetString(const char* a, const char* b, const char* c)
+{
+
+}
+char* wPrefGetString(const char* section, const char* name)
+{
+ return("");
}
-wPrefSetString()
+void AbortProg(const char* a, const char* b, int c, const char*d)
{
}
-wPrefGetString()
+void *
+MyMalloc(size_t size)
{
+ return(malloc(size));
+}
+void
+MyFree(void* memory)
+{
+ free(memory);
}
-AbortProg()
+char *
+MyStrdup(const char* string)
{
+ return(strdup(string));
+}
+void *
+MyRealloc(void *memory, size_t size)
+{
+ return(realloc(memory, size));
}
static void
@@ -49,8 +76,8 @@ static void ScanEmptyDir(void **state)
{
(void)state;
bool success;
- EmptyCatalog(trackLib->catalog);
- success = GetTrackFiles(trackLib, "//");
+ DestroyCatalog(trackLib->catalog);
+ success = CreateCatalogFromDir(trackLib, "//");
assert_false(success);
}
@@ -58,8 +85,8 @@ static void ScanTestFiles(void **state)
{
(void)state;
bool success;
- EmptyCatalog(trackLib->catalog);
- success = GetTrackFiles(trackLib, ".");
+ DestroyCatalog(trackLib->catalog);
+ success = CreateCatalogFromDir(trackLib, ".");
assert_true(success);
}
@@ -73,25 +100,25 @@ static void CreateIndex(void **state)
static void SearchNothing(void **state)
{
(void)state;
- unsigned int files = SearchLibrary(trackLib, "djfhdkljhf", catalog);
+ unsigned int files = SearchLibrary(trackLib, "djfhdkljhf", result);
assert_true(files == 0);
- EmptyCatalog(catalog);
+ SearchDiscardResult(result);
}
static void SearchSingle(void **state)
{
(void)state;
- int files = SearchLibrary(trackLib, "peco", catalog );
+ int files = SearchLibrary(trackLib, "peco", result );
assert_true(files==1);
- EmptyCatalog(catalog);
+ SearchDiscardResult(result);
}
static void SearchMultiple(void **state)
{
(void)state;
- int files = SearchLibrary(trackLib, "atlas", catalog);
+ int files = SearchLibrary(trackLib, "atlas", result);
assert_true(files == 2);
- EmptyCatalog(catalog);
+ SearchDiscardResult(result);
}
static void FilterTest(void **state)
@@ -107,7 +134,7 @@ static void FilterTest(void **state)
int main(void)
{
- const struct CMUnitTest tests[] = {
+ const struct CMUnitTest tests[] = {
cmocka_unit_test(CreateLib),
cmocka_unit_test(ScanEmptyDir),
cmocka_unit_test(ScanTestFiles),
@@ -116,9 +143,9 @@ int main(void)
cmocka_unit_test(SearchSingle),
cmocka_unit_test(SearchMultiple),
cmocka_unit_test(FilterTest),
- };
+ };
catalog = InitCatalog();
- return cmocka_run_group_tests(tests, NULL, NULL);
+ return cmocka_run_group_tests(tests, NULL, NULL);
} \ No newline at end of file
diff --git a/app/bin/unittest/defaultstest.c b/app/bin/unittest/defaultstest.c
index e930468..06ae304 100644
--- a/app/bin/unittest/defaultstest.c
+++ b/app/bin/unittest/defaultstest.c
@@ -24,13 +24,13 @@ struct appDefault tests[] = {
const char *libDir ="Parameter/directory/";
/**
- * A dummy for the real MakePath function
+ * A dummy for the real MakePath function
*/
void
MakeFullpath( char **result, ...)
{
- *result = libDir;
+ *result = libDir;
}
#define TESTARRAYSIZE (sizeof(tests) / sizeof(tests[0]) )
@@ -43,14 +43,16 @@ struct appDefault test1[] = {
int
-wPrefGetIntegerBasic(const char *section, const char *name, long *result, long defaultValue)
+wPrefGetIntegerBasic(const char *section, const char *name, long *result,
+ long defaultValue)
{
*result = defaultValue;
return(TRUE);
}
int
-wPrefGetFloatBasic(const char *section, const char *name, double *result, double defaultValue)
+wPrefGetFloatBasic(const char *section, const char *name, double *result,
+ double defaultValue)
{
*result = defaultValue;
return(TRUE);
@@ -62,7 +64,7 @@ char * wPrefGetStringBasic(const char *section, const char *name)
}
/* dummy to make the linker happy */
-void
+void
wPrefSetInteger(const char *section, const char *name, long value)
{
return;
@@ -108,9 +110,9 @@ static void GetDefaults(void **state)
int main(void)
{
- const struct CMUnitTest tests[] = {
+ const struct CMUnitTest tests[] = {
cmocka_unit_test(BinarySearch),
cmocka_unit_test(GetDefaults)
- };
- return cmocka_run_group_tests(tests, NULL, NULL);
+ };
+ return cmocka_run_group_tests(tests, NULL, NULL);
}
diff --git a/app/bin/unittest/dxfformattest.c b/app/bin/unittest/dxfformattest.c
index b797ad9..3c5474a 100644
--- a/app/bin/unittest/dxfformattest.c
+++ b/app/bin/unittest/dxfformattest.c
@@ -45,9 +45,10 @@ static void LineCommand(void **state)
DynStringMalloc(&string, 0);
- DxfLineCommand( &string, 0, 1.0, 2.0, 1.1, 2.2, 1);
+ DxfLineCommand( &string, 0, 1.0, 2.0, 1.1, 2.2, 1, 1);
assert_string_equal(DynStringToCStr(&string),
- DXF_INDENT "0\nLINE\n 8\nXTRKCAD0\n 10\n1.000000\n 20\n2.000000\n 11\n1.100000\n 21\n2.200000\n 6\nDASHED\n");
+ DXF_INDENT "0\nLINE\n 8\nXTRKCAD0\n 10\n1.000000\n 20\n2.000000"
+ "\n 11\n1.100000\n 21\n2.200000\n 6\nDASHEDTINY\n 420\n1\n");
DynStringFree(&string);
}
@@ -60,9 +61,10 @@ static void CircleCommand(void **state)
DynStringMalloc(&string, 0);
- DxfCircleCommand(&string, 0, 1.0, 2.0, 1.1, 1);
+ DxfCircleCommand(&string, 0, 1.0, 2.0, 1.1, 1, 1);
assert_string_equal(DynStringToCStr(&string),
- DXF_INDENT "0\nCIRCLE\n 10\n1.000000\n 20\n2.000000\n 40\n1.100000\n 8\nXTRKCAD0\n 6\nDASHED\n");
+ DXF_INDENT "0\nCIRCLE\n 10\n1.000000\n 20\n2.000000\n"
+ " 40\n1.100000\n 8\nXTRKCAD0\n 6\nDASHEDTINY\n 420\n1\n");
DynStringFree(&string);
}
@@ -75,9 +77,10 @@ static void ArcCommand(void **state)
DynStringMalloc(&string, 0);
- DxfArcCommand(&string, 0, 1.0, 2.0, 1.1, 10.0, 180.0, 1);
+ DxfArcCommand(&string, 0, 1.0, 2.0, 1.1, 10.0, 180.0, 1, 1);
assert_string_equal(DynStringToCStr(&string),
- DXF_INDENT "0\nARC\n 10\n1.000000\n 20\n2.000000\n 40\n1.100000\n 50\n10.000000\n 51\n190.000000\n 8\nXTRKCAD0\n 6\nDASHED\n");
+ DXF_INDENT "0\nARC\n 10\n1.000000\n 20\n2.000000\n 40\n1.100000\n"
+ " 50\n10.000000\n 51\n190.000000\n 8\nXTRKCAD0\n 6\nDASHEDTINY\n 420\n1\n");
DynStringFree(&string);
}
@@ -91,10 +94,11 @@ static void TextCommand(void **state)
DynStringMalloc(&string, 0);
- DxfTextCommand(&string, 0, 10.0, 12.0, 144.0, TESTSTRING);
+ DxfTextCommand(&string, 0, 10.0, 12.0, 144.0, TESTSTRING, 1);
assert_string_equal(DynStringToCStr(&string),
- DXF_INDENT "0\nTEXT\n 1\n" TESTSTRING "\n 10\n10.000000\n 20\n12.000000\n 40\n2.000000\n 8\nXTRKCAD0\n");
+ DXF_INDENT "0\nTEXT\n 1\n" TESTSTRING "\n 10\n10.000000\n 20\n12.000000\n"
+ " 40\n2.000000\n 8\nXTRKCAD0\n 420\n1\n");
DynStringFree(&string);
}
@@ -109,36 +113,40 @@ static void Units(void **state)
/* test English units */
units = 0;
DxfUnits(&string);
- assert_string_equal(DynStringToCStr(&string), DXF_INDENT "9\n$MEASUREMENT\n 70\n0\n" DXF_INDENT "9\n$INSUNITS\n 70\n1\n");
+ assert_string_equal(DynStringToCStr(&string),
+ DXF_INDENT "9\n$MEASUREMENT\n 70\n0\n" DXF_INDENT "9\n$INSUNITS\n 70\n1\n");
DxfFormatPosition(&string, 20, 1.23456789);
assert_string_equal(DynStringToCStr(&string), DXF_INDENT "20\n1.234568\n");
-
+
DynStringClear(&string);
DxfDimensionSize(&string, DXF_DIMTEXTSIZE);
- assert_string_equal(DynStringToCStr(&string), DXF_INDENT "9\n$DIMTXT\n 40\n1.0\n");
+ assert_string_equal(DynStringToCStr(&string),
+ DXF_INDENT "9\n$DIMTXT\n 40\n1.0\n");
/* test metric units */
units = 1;
DynStringClear(&string);
DxfUnits(&string);
- assert_string_equal(DynStringToCStr(&string), DXF_INDENT "9\n$MEASUREMENT\n 70\n1\n" DXF_INDENT "9\n$INSUNITS\n 70\n4\n");
+ assert_string_equal(DynStringToCStr(&string),
+ DXF_INDENT "9\n$MEASUREMENT\n 70\n1\n" DXF_INDENT "9\n$INSUNITS\n 70\n4\n");
DxfFormatPosition(&string, 20, 1.23456789);
assert_string_equal(DynStringToCStr(&string), DXF_INDENT "20\n31.358024\n");
DynStringClear(&string);
DxfDimensionSize(&string, DXF_DIMTEXTSIZE);
- assert_string_equal(DynStringToCStr(&string), DXF_INDENT "9\n$DIMTXT\n 40\n25.0\n");
+ assert_string_equal(DynStringToCStr(&string),
+ DXF_INDENT "9\n$DIMTXT\n 40\n25.0\n");
}
int main(void)
{
- const struct CMUnitTest tests[] = {
+ const struct CMUnitTest tests[] = {
cmocka_unit_test(BasicFormatting),
cmocka_unit_test(LineCommand),
cmocka_unit_test(CircleCommand),
cmocka_unit_test(ArcCommand),
cmocka_unit_test(TextCommand),
cmocka_unit_test(Units)
- };
- return cmocka_run_group_tests(tests, NULL, NULL);
+ };
+ return cmocka_run_group_tests(tests, NULL, NULL);
} \ No newline at end of file
diff --git a/app/bin/unittest/pathstest.c b/app/bin/unittest/pathstest.c
index 3ee830e..eccba24 100644
--- a/app/bin/unittest/pathstest.c
+++ b/app/bin/unittest/pathstest.c
@@ -32,6 +32,9 @@
#define DEFAULTPATH "/Default/Path"
#endif //WINDOWS
+
+// Dummy functions to satisfy the linker
+
void
wPrefSetString(const char *section, const char *key, const char *value)
{}
@@ -51,6 +54,11 @@ const char *wGetUserHomeDir(void)
return(DEFAULTPATH);
}
+void AbortProg(const char *a, const char *b, int d, const char *c)
+{
+ return;
+}
+
#include "../paths.c"
static void SetGetPath(void **state)
@@ -67,7 +75,7 @@ static void SetGetPath(void **state)
SetCurrentPath("Test", TESTFILE2);
string = GetCurrentPath("Test");
- assert_string_equal(string, TESTPATH2);
+ assert_string_equal(string, TESTPATH2);
}
static void Makepath(void **state)
@@ -76,38 +84,38 @@ static void Makepath(void **state)
char *path;
#ifdef WINDOWS
- MakeFullpath(&path,
- "C:",
- TESTRELATIVEPATH,
- TESTFILENAME,
- NULL);
+ MakeFullpath(&path,
+ "C:",
+ TESTRELATIVEPATH,
+ TESTFILENAME,
+ NULL);
- assert_string_equal(path, "C:" TESTRELATIVEPATH "\\" TESTFILENAME);
+ assert_string_equal(path, "C:" TESTRELATIVEPATH "\\" TESTFILENAME);
#else
- MakeFullpath(&path,
- TESTRELATIVEPATH,
- TESTFILENAME,
- NULL);
+ MakeFullpath(&path,
+ TESTRELATIVEPATH,
+ TESTFILENAME,
+ NULL);
- assert_string_equal(path, TESTRELATIVEPATH "/" TESTFILENAME);
+ assert_string_equal(path, TESTRELATIVEPATH "/" TESTFILENAME);
#endif // WINDOWS
free(path);
#ifdef WINDOWS
MakeFullpath(&path,
- "C:",
- "test",
- "\\subdir",
- TESTFILENAME,
- NULL);
+ "C:",
+ "test",
+ "\\subdir",
+ TESTFILENAME,
+ NULL);
assert_string_equal(path, "C:test\\subdir\\" TESTFILENAME);
#else
MakeFullpath(&path,
- "test",
- "/subdir",
- TESTFILENAME,
- NULL);
+ "test",
+ "/subdir",
+ TESTFILENAME,
+ NULL);
assert_string_equal(path, "test/subdir/" TESTFILENAME);
#endif // WINDOWS
@@ -118,9 +126,9 @@ static void Makepath(void **state)
int main(void)
{
- const struct CMUnitTest tests[] = {
+ const struct CMUnitTest tests[] = {
cmocka_unit_test(SetGetPath),
cmocka_unit_test(Makepath),
- };
- return cmocka_run_group_tests(tests, NULL, NULL);
+ };
+ return cmocka_run_group_tests(tests, NULL, NULL);
}
diff --git a/app/bin/unittest/shortentest.c b/app/bin/unittest/shortentest.c
index 4d24b84..9288017 100644
--- a/app/bin/unittest/shortentest.c
+++ b/app/bin/unittest/shortentest.c
@@ -111,7 +111,7 @@ static void EllipsizeText(void **state)
EllipsizeString(LONGSTRING, result, strlen(LONGSTRING));
assert_string_equal(result, LONGSTRING);
- EllipsizeString(LONGSTRING, result, 40);
+ EllipsizeString(LONGSTRING, result, 40);
assert_string_equal(result, "The strrchr() function in C/C++...");
EllipsizeString(LONGSTRING, result, 23);
@@ -138,7 +138,7 @@ static void LongText(void **state)
int main(void)
{
- const struct CMUnitTest tests[] = {
+ const struct CMUnitTest tests[] = {
cmocka_unit_test(NoRemoveBlanks),
cmocka_unit_test(RemoveMultipleBlanks),
cmocka_unit_test(RemoveTabs),
@@ -147,6 +147,6 @@ int main(void)
cmocka_unit_test(NoEllipsizeText),
cmocka_unit_test(EllipsizeText),
cmocka_unit_test(LongText),
- };
- return cmocka_run_group_tests(tests, NULL, NULL);
+ };
+ return cmocka_run_group_tests(tests, NULL, NULL);
} \ No newline at end of file
diff --git a/app/bin/unittest/testfiles/HO-Peco-Code83.xtp b/app/bin/unittest/testfiles/HO-Peco-Code83.xtp
index 09bf426..681e6f5 100644
--- a/app/bin/unittest/testfiles/HO-Peco-Code83.xtp
+++ b/app/bin/unittest/testfiles/HO-Peco-Code83.xtp
@@ -130,8 +130,10 @@ END
SUBCONTENTS Peco Code 83 HO Slip Turnouts
TURNOUT HO "Peco Code 83 #6 Double Slip Switch SL-U8363"
- P "Normal" 1 2 3 0 4 5 6
- P "Reverse" 1 7 6 0 4 8 3
+ P "Cross1" 1 2 3
+ P "Cross2" 4 5 6
+ P "Slip1" 1 7 6
+ P "Slip2" 4 8 3
E 0.000000 0.000000 270.000000
E 12.035433 0.000000 90.000000
E 0.082528 0.993201 279.500000