summaryrefslogtreecommitdiff
path: root/common/tests/test-path.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/tests/test-path.c')
-rw-r--r--common/tests/test-path.c131
1 files changed, 66 insertions, 65 deletions
diff --git a/common/tests/test-path.c b/common/tests/test-path.c
index 8263d1f..ec2c200 100644
--- a/common/tests/test-path.c
+++ b/common/tests/test-path.c
@@ -33,7 +33,7 @@
*/
#include "config.h"
-#include "CuTest.h"
+#include "test.h"
#include <stdlib.h>
#include <stdio.h>
@@ -43,7 +43,7 @@
#include "path.h"
static void
-test_base (CuTest *tc)
+test_base (void)
{
struct {
const char *in;
@@ -70,133 +70,134 @@ test_base (CuTest *tc)
for (i = 0; fixtures[i].in != NULL; i++) {
out = p11_path_base (fixtures[i].in);
- CuAssertStrEquals (tc, fixtures[i].out, out);
+ assert_str_eq (fixtures[i].out, out);
free (out);
}
}
-static void
-check_equals_and_free_msg (CuTest *tc,
- const char *file,
- int line,
- const char *ex,
- char *ac)
-{
- CuAssertStrEquals_LineMsg (tc, file, line, NULL, ex, ac);
- free (ac);
-}
-
-#define check_equals_and_free(tc, ex, ac) \
- check_equals_and_free_msg ((tc), __FILE__, __LINE__, (ex), (ac))
+#define check_equals_and_free(ex, ac) \
+ do { assert_str_eq (ex, ac); free (ac); } while (0)
static void
-test_build (CuTest *tc)
+test_build (void)
{
#ifdef OS_UNIX
- check_equals_and_free (tc, "/root/second",
+ check_equals_and_free ("/root/second",
p11_path_build ("/root", "second", NULL));
- check_equals_and_free (tc, "/root/second",
+ check_equals_and_free ("/root/second",
p11_path_build ("/root", "/second", NULL));
- check_equals_and_free (tc, "/root/second",
+ check_equals_and_free ("/root/second",
p11_path_build ("/root/", "second", NULL));
- check_equals_and_free (tc, "/root/second/third",
+ check_equals_and_free ("/root/second/third",
p11_path_build ("/root", "second", "third", NULL));
- check_equals_and_free (tc, "/root/second/third",
+ check_equals_and_free ("/root/second/third",
p11_path_build ("/root", "/second/third", NULL));
#else /* OS_WIN32 */
- check_equals_and_free (tc, "C:\\root\\second",
+ check_equals_and_free ("C:\\root\\second",
p11_path_build ("C:\\root", "second", NULL));
- check_equals_and_free (tc, "C:\\root\\second",
+ check_equals_and_free ("C:\\root\\second",
p11_path_build ("C:\\root", "\\second", NULL));
- check_equals_and_free (tc, "C:\\root\\second",
+ check_equals_and_free ("C:\\root\\second",
p11_path_build ("C:\\root\\", "second", NULL));
- check_equals_and_free (tc, "C:\\root\\second\\third",
+ check_equals_and_free ("C:\\root\\second\\third",
p11_path_build ("C:\\root", "second", "third", NULL));
- check_equals_and_free (tc, "C:\\root\\second/third",
+ check_equals_and_free ("C:\\root\\second/third",
p11_path_build ("C:\\root", "second/third", NULL));
#endif
}
static void
-test_expand (CuTest *tc)
+test_expand (void)
{
char *path;
#ifdef OS_UNIX
putenv ("HOME=/home/blah");
- check_equals_and_free (tc, "/home/blah/my/path",
+ check_equals_and_free ("/home/blah/my/path",
p11_path_expand ("$HOME/my/path"));
- check_equals_and_free (tc, "/home/blah/my/path",
+ check_equals_and_free ("/home/blah/my/path",
p11_path_expand ("~/my/path"));
+ check_equals_and_free ("/home/blah",
+ p11_path_expand ("$HOME"));
+ check_equals_and_free ("/home/blah",
+ p11_path_expand ("~"));
putenv ("TEMP=/tmpdir");
- check_equals_and_free (tc, "/tmpdir/my/path",
+ check_equals_and_free ("/tmpdir/my/path",
p11_path_expand ("$TEMP/my/path"));
+ check_equals_and_free ("/tmpdir",
+ p11_path_expand ("$TEMP"));
#else /* OS_WIN32 */
putenv ("HOME=C:\\Users\\blah");
- check_equals_and_free (tc, "C:\\Users\\blah\\path",
+ check_equals_and_free ("C:\\Users\\blah\\path",
p11_path_expand ("$HOME/path"));
- check_equals_and_free (tc, "C:\\Users\\blah\\path",
+ check_equals_and_free ("C:\\Users\\blah\\path",
p11_path_expand ("$HOME\\path"));
- check_equals_and_free (tc, "C:\\Users\\blah\\path",
+ check_equals_and_free ("C:\\Users\\blah\\path",
p11_path_expand ("~/path"));
- check_equals_and_free (tc, "C:\\Users\\blah\\path",
+ check_equals_and_free ("C:\\Users\\blah\\path",
p11_path_expand ("~\\path"));
putenv ("TEMP=C:\\Temp Directory");
- check_equals_and_free (tc, "C:\\Temp Directory\\path",
+ check_equals_and_free ("C:\\Temp Directory\\path",
p11_path_expand ("$TEMP/path"));
- check_equals_and_free (tc, "C:\\Temp Directory\\path",
+ check_equals_and_free ("C:\\Temp Directory\\path",
p11_path_expand ("$TEMP\\path"));
#endif
putenv("HOME=");
path = p11_path_expand ("$HOME/this/is/my/path");
- CuAssertTrue (tc, strstr (path, "this/is/my/path") != NULL);
+ assert (strstr (path, "this/is/my/path") != NULL);
free (path);
putenv("HOME=");
path = p11_path_expand ("~/this/is/my/path");
- CuAssertTrue (tc, strstr (path, "this/is/my/path") != NULL);
+ assert (strstr (path, "this/is/my/path") != NULL);
free (path);
putenv("TEMP=");
path = p11_path_expand ("$TEMP/this/is/my/path");
- CuAssertTrue (tc, strstr (path, "this/is/my/path") != NULL);
+ assert (strstr (path, "this/is/my/path") != NULL);
free (path);
}
static void
-test_absolute (CuTest *tc)
+test_absolute (void)
{
#ifdef OS_UNIX
- CuAssertTrue (tc, p11_path_absolute ("/home"));
- CuAssertTrue (tc, !p11_path_absolute ("home"));
+ assert (p11_path_absolute ("/home"));
+ assert (!p11_path_absolute ("home"));
#else /* OS_WIN32 */
- CuAssertTrue (tc, p11_path_absolute ("C:\\home"));
- CuAssertTrue (tc, !p11_path_absolute ("home"));
- CuAssertTrue (tc, !p11_path_absolute ("/home"));
+ assert (p11_path_absolute ("C:\\home"));
+ assert (!p11_path_absolute ("home"));
+ assert (p11_path_absolute ("/home"));
#endif
}
+static void
+test_parent (void)
+{
+ check_equals_and_free ("/", p11_path_parent ("/root"));
+ check_equals_and_free ("/", p11_path_parent ("/root/"));
+ check_equals_and_free ("/", p11_path_parent ("/root//"));
+ check_equals_and_free ("/root", p11_path_parent ("/root/second"));
+ check_equals_and_free ("/root", p11_path_parent ("/root//second"));
+ check_equals_and_free ("/root", p11_path_parent ("/root//second//"));
+ check_equals_and_free ("/root", p11_path_parent ("/root///second"));
+ check_equals_and_free ("/root/second", p11_path_parent ("/root/second/test.file"));
+ assert_ptr_eq (NULL, p11_path_parent ("/"));
+ assert_ptr_eq (NULL, p11_path_parent ("//"));
+ assert_ptr_eq (NULL, p11_path_parent (""));
+}
+
int
-main (void)
+main (int argc,
+ char *argv[])
{
- CuString *output = CuStringNew ();
- CuSuite* suite = CuSuiteNew ();
- int ret;
-
- SUITE_ADD_TEST (suite, test_base);
- SUITE_ADD_TEST (suite, test_build);
- SUITE_ADD_TEST (suite, test_expand);
- SUITE_ADD_TEST (suite, test_absolute);
-
- CuSuiteRun (suite);
- CuSuiteSummary (suite, output);
- CuSuiteDetails (suite, output);
- printf ("%s\n", output->buffer);
- ret = suite->failCount;
- CuSuiteDelete (suite);
- CuStringDelete (output);
-
- return ret;
+ p11_test (test_base, "/path/base");
+ p11_test (test_build, "/path/build");
+ p11_test (test_expand, "/path/expand");
+ p11_test (test_absolute, "/path/absolute");
+ p11_test (test_parent, "/path/parent");
+
+ return p11_test_run (argc, argv);
}