示例#1
0
static void TestGetDir(void)
{
    int i;
    char dirname[100];

    // Test the standard strings.
    for (i = 0; i < NUM_TEST_STRS; i++)
    {
        LE_TEST( (le_path_GetDir(PathNames[i], "/", dirname, 100) == LE_OK) &&
                  (strcmp(dirname, DirNames[i]) == 0) );
        LE_DEBUG("Dir: '%s'", dirname);
    }

    // Test with multibyte separators.
    for (i = 0; i < NUM_TEST_STRS; i++)
    {
        LE_TEST( (le_path_GetDir(SepPathNames[i], "**", dirname, 100) == LE_OK) &&
                  (strcmp(dirname, SepDirNames[i]) == 0) );
        LE_DEBUG("Dir: '%s'", dirname);
    }

    // Test an overflow condition.
    LE_TEST( (le_path_GetDir(PathNames[1], "/", dirname, 21) == LE_OVERFLOW) &&
             (strcmp(dirname, "/long/path/with/trai") == 0) );
    LE_DEBUG("Dir: '%s'", dirname);
}
示例#2
0
//--------------------------------------------------------------------------------------------------
static void MsgRecvHandler
(
    le_msg_MessageRef_t msgRef,             ///< Reference to the received message.
    void*               opaqueContextPtr    ///< contextPtr passed to le_msg_SetServiceRecvHandler()
)
//--------------------------------------------------------------------------------------------------
{
    Context_t* contextPtr = opaqueContextPtr;

    LE_ASSERT(contextPtr != NULL);
    LE_TEST(contextPtr->strPtr == ContextStr);
    LE_TEST(strcmp(contextPtr->strPtr, ContextStr) == 0);

    le_msg_SessionRef_t sessionRef = le_msg_GetSession(msgRef);
    LE_ASSERT(sessionRef != NULL);

    burger_Message_t* msgPtr = le_msg_GetPayloadPtr(msgRef);
    LE_ASSERT(msgPtr != NULL);

    LE_INFO("Received '%x'", msgPtr->payload);

    switch (msgPtr->payload)
    {
        case 0xBEEFBEEF:
            LE_TEST(le_msg_NeedsResponse(msgRef) == false);
            le_msg_ReleaseMsg(msgRef);

            break;

        case 0xDEADBEEF:
            LE_TEST(le_msg_NeedsResponse(msgRef) == true);
            contextPtr->requestCount++;
            LE_INFO("Received transaction request (%d/%d).",
                    contextPtr->requestCount,
                    contextPtr->maxRequestCount);

            // Construct and send response.
            msgPtr->payload = 0xBEEFDEAD;
            le_msg_Respond(msgRef);

            // If we have received the magic number of requests, tell the client to
            // terminate the test by sending 0xDEADDEAD to the client.
            if (contextPtr->requestCount >= contextPtr->maxRequestCount)
            {
                LE_INFO("Maximum number of request-response transactions reached.");
                msgRef = le_msg_CreateMsg(sessionRef);
                msgPtr = le_msg_GetPayloadPtr(msgRef);
                msgPtr->payload = 0xDEADDEAD;
                le_msg_Send(msgRef);
            }
            break;

        default:
            LE_FATAL("Unexpected message payload (%x)", msgPtr->payload);
    }
}
示例#3
0
static void TestGetBasenamePtr(void)
{
    int i;
    char* basenamePtr;

    // Test the standard strings.
    for (i = 0; i < NUM_TEST_STRS; i++)
    {
        basenamePtr = le_path_GetBasenamePtr(PathNames[i], "/");
        LE_DEBUG("Basename: '%s'", basenamePtr);
        LE_TEST(strcmp(basenamePtr, BaseNames[i]) == 0);
    }

    // Test with multibyte separators.
    for (i = 0; i < NUM_TEST_STRS; i++)
    {
        basenamePtr = le_path_GetBasenamePtr(SepPathNames[i], "**");
        LE_DEBUG("Basename: '%s'", basenamePtr);
        LE_TEST(strcmp(basenamePtr, BaseNames[i]) == 0);
    }
}
示例#4
0
//--------------------------------------------------------------------------------------------------
static void NewSessionHandler
(
    le_msg_SessionRef_t sessionRef,
    void*               contextPtr
)
//--------------------------------------------------------------------------------------------------
{
    LE_INFO("Client started a new session.");

    LE_INFO("contextPtr = %p.", contextPtr);
    LE_TEST(contextPtr == &ServiceOpenContextPtr);

    // Because the unit tests are run always as a single, non-root user, we expect the user ID
    // of the client to be the same user ID that we are running as.
    uid_t clientUserId;
    uid_t myUserId = getuid();
    le_result_t result = le_msg_GetClientUserId(sessionRef, &clientUserId);
    LE_INFO("le_msg_GetClientUserId() returned '%s' with UID %u.",
            LE_RESULT_TXT(result),
            clientUserId);
    LE_INFO("getuid() returned %u.", myUserId);
    LE_TEST(clientUserId == myUserId);
}
示例#5
0
static void IteratePath
(
    le_pathIter_Ref_t iteratorRef,
    const char* originalPath,
    const char* nodes[]
)
{
    char fullPath[LARGE_BUFFER_SIZE] = { 0 };

    le_pathIter_GetPath(iteratorRef, fullPath, LARGE_BUFFER_SIZE);

    LE_INFO("Iterating path %s.", fullPath);
    LE_TEST(strcmp(fullPath, originalPath) == 0);

    le_pathIter_GoToStart(iteratorRef);
    ssize_t index = 0;

    LE_INFO(">>>> Forward Iteration >>>>");

    do
    {
        char buffer[LARGE_BUFFER_SIZE] = { 0 };

        LE_TEST(le_pathIter_GetCurrentNode(iteratorRef,
                                            buffer,
                                            LARGE_BUFFER_SIZE) != LE_OVERFLOW);
        LE_INFO("> Found: %s, Expect: %s", buffer, nodes[index]);
        LE_TEST(strcmp(buffer, nodes[index]) == 0);
        index++;
    }
    while (le_pathIter_GoToNext(iteratorRef) != LE_NOT_FOUND);

    --index;

    LE_INFO("<<<< Reverse Iteration <<<<");

    le_pathIter_GoToEnd(iteratorRef);

    do
    {
        char buffer[LARGE_BUFFER_SIZE] = { 0 };

        LE_TEST(le_pathIter_GetCurrentNode(iteratorRef,
                                            buffer,
                                            LARGE_BUFFER_SIZE) != LE_OVERFLOW);
        LE_INFO("< Found: %s, Expect: %s", buffer, nodes[index]);
        LE_TEST(strcmp(buffer, nodes[index]) == 0);
        index--;
    }
    while (le_pathIter_GoToPrev(iteratorRef) != LE_NOT_FOUND);

    LE_TEST(index == -1);
}
示例#6
0
static void TestUnixStyleAppends(void)
{
    LE_INFO("======== Test Unix Style Appends.");

    {
        le_pathIter_Ref_t iteratorRef = le_pathIter_CreateForUnix("/a/b/c");
        LE_TEST(le_pathIter_Append(iteratorRef, "x/y/z") == LE_OK);
        LE_TEST(TestPath(iteratorRef, "/a/b/c/x/y/z"));
        LE_TEST(le_pathIter_IsAbsolute(iteratorRef) == true);
        le_pathIter_Delete(iteratorRef);
    }

    {
        le_pathIter_Ref_t iteratorRef = le_pathIter_CreateForUnix("/a/b/c");
        LE_TEST(le_pathIter_Append(iteratorRef, "../x/y/z") == LE_OK);
        LE_TEST(TestPath(iteratorRef, "/a/b/x/y/z"));
        LE_TEST(le_pathIter_IsAbsolute(iteratorRef) == true);
        le_pathIter_Delete(iteratorRef);
    }

    {
        le_pathIter_Ref_t iteratorRef = le_pathIter_CreateForUnix("/a/b/c");
        LE_TEST(le_pathIter_Append(iteratorRef, "../../x/y/z") == LE_OK);
        LE_TEST(TestPath(iteratorRef, "/a/x/y/z"));
        LE_TEST(le_pathIter_IsAbsolute(iteratorRef) == true);
        le_pathIter_Delete(iteratorRef);
    }

    {
        le_pathIter_Ref_t iteratorRef = le_pathIter_CreateForUnix("/a/b/c");
        LE_TEST(le_pathIter_Append(iteratorRef, "../../../x/y/z") == LE_OK);
        LE_TEST(TestPath(iteratorRef, "/x/y/z"));
        LE_TEST(le_pathIter_IsAbsolute(iteratorRef) == true);
        le_pathIter_Delete(iteratorRef);
    }

    {
        le_pathIter_Ref_t iteratorRef = le_pathIter_CreateForUnix("/a/b/c");
        LE_TEST(le_pathIter_Append(iteratorRef, "../../../../x/y/z") == LE_UNDERFLOW);
        LE_TEST(TestPath(iteratorRef, "/"));
        LE_TEST(le_pathIter_IsAbsolute(iteratorRef) == true);
        le_pathIter_Delete(iteratorRef);
    }

    {
        le_pathIter_Ref_t iteratorRef = le_pathIter_CreateForUnix("a/b/c");
        LE_TEST(le_pathIter_Append(iteratorRef, "../../../x/y/z") == LE_OK);
        LE_TEST(TestPath(iteratorRef, "x/y/z"));
        LE_TEST(le_pathIter_IsAbsolute(iteratorRef) == false);
        le_pathIter_Delete(iteratorRef);
    }

    {
        le_pathIter_Ref_t iteratorRef = le_pathIter_CreateForUnix("a/b/c");
        LE_TEST(le_pathIter_Append(iteratorRef, "../../../../x/y/z") == LE_OK);
        LE_TEST(TestPath(iteratorRef, "../x/y/z"));
        LE_TEST(le_pathIter_IsAbsolute(iteratorRef) == false);
        le_pathIter_Delete(iteratorRef);
    }

    {
        le_pathIter_Ref_t iteratorRef = le_pathIter_CreateForUnix("/a/b/c");
        LE_TEST(le_pathIter_Append(iteratorRef, "/x/y/z") == LE_OK);
        LE_TEST(TestPath(iteratorRef, "/x/y/z"));
        LE_TEST(le_pathIter_IsAbsolute(iteratorRef) == true);
        le_pathIter_Delete(iteratorRef);
    }

    {
        le_pathIter_Ref_t iteratorRef = le_pathIter_CreateForUnix("a/b/c");
        LE_TEST(le_pathIter_Append(iteratorRef, "/x/y/z") == LE_OK);
        LE_TEST(TestPath(iteratorRef, "/x/y/z"));
        LE_TEST(le_pathIter_IsAbsolute(iteratorRef) == true);
        le_pathIter_Delete(iteratorRef);
    }

    {
        le_pathIter_Ref_t iteratorRef = le_pathIter_CreateForUnix("a/b/c");
        LE_TEST(le_pathIter_Append(iteratorRef, "./x/y/z") == LE_OK);
        LE_TEST(TestPath(iteratorRef, "a/b/c/x/y/z"));
        LE_TEST(le_pathIter_IsAbsolute(iteratorRef) == false);
        le_pathIter_Delete(iteratorRef);
    }

    {
        le_pathIter_Ref_t iteratorRef = le_pathIter_CreateForUnix("");
        LE_TEST(le_pathIter_Append(iteratorRef, "./x/y/./z") == LE_OK);
        LE_TEST(TestPath(iteratorRef, "./x/y/z"));
        LE_TEST(le_pathIter_IsAbsolute(iteratorRef) == false);
        le_pathIter_Delete(iteratorRef);
    }

    {
        le_pathIter_Ref_t iteratorRef = le_pathIter_CreateForUnix("");
        LE_TEST(le_pathIter_Append(iteratorRef, "/a//path/to/a///some/../place") == LE_OK);
        LE_TEST(TestPath(iteratorRef, "/a/path/to/a/place"));
        LE_TEST(le_pathIter_IsAbsolute(iteratorRef) == true);
        le_pathIter_Delete(iteratorRef);
    }

    {
        le_pathIter_Ref_t iteratorRef = le_pathIter_Create("", "::", "^^", "__");
        LE_TEST(le_pathIter_Append(iteratorRef, "__::a::::path::to::__::a::some::^^::place") == LE_OK);
        LE_TEST(TestPath(iteratorRef, "__::a::path::to::a::place"));
        LE_TEST(le_pathIter_IsAbsolute(iteratorRef) == false);
        le_pathIter_Delete(iteratorRef);
    }

    {
        le_pathIter_Ref_t iteratorRef = le_pathIter_Create("::", "::", "^^", "__");
        LE_TEST(le_pathIter_Append(iteratorRef, "__::a::::path::to::__::a::some::^^::place") == LE_OK);
        LE_TEST(TestPath(iteratorRef, "::a::path::to::a::place"));
        LE_TEST(le_pathIter_IsAbsolute(iteratorRef) == true);
        le_pathIter_Delete(iteratorRef);
    }

    {
        le_pathIter_Ref_t iteratorRef = le_pathIter_Create("", "/", NULL, NULL);
        LE_TEST(le_pathIter_Append(iteratorRef, "/a//path/./to/a///some/../place") == LE_OK);
        LE_TEST(TestPath(iteratorRef, "/a/path/./to/a/some/../place"));
        LE_TEST(le_pathIter_IsAbsolute(iteratorRef) == true);
        le_pathIter_Delete(iteratorRef);
    }

    {
        le_pathIter_Ref_t iteratorRef = le_pathIter_CreateForUnix("");
        LE_TEST(le_pathIter_Append(iteratorRef, "../../../a//path/") == LE_OK);
        LE_TEST(TestPath(iteratorRef, "../../../a/path"));
        LE_TEST(le_pathIter_IsAbsolute(iteratorRef) == false);
        le_pathIter_Delete(iteratorRef);
    }

    {
        le_pathIter_Ref_t iteratorRef = le_pathIter_CreateForUnix("");
        LE_TEST(le_pathIter_Append(iteratorRef, "/a//path/to/a///some/../place") == LE_OK);
        LE_TEST(TestPath(iteratorRef, "/a/path/to/a/place"));
        LE_TEST(le_pathIter_IsAbsolute(iteratorRef) == true);

        LE_TEST(le_pathIter_GoToStart(iteratorRef) == LE_OK);

        LE_TEST(le_pathIter_GoToNext(iteratorRef) == LE_OK);
        LE_TEST(le_pathIter_GoToNext(iteratorRef) == LE_OK);
        LE_TEST(le_pathIter_GoToNext(iteratorRef) == LE_OK);

        le_pathIter_Truncate(iteratorRef);

        LE_TEST(le_pathIter_Append(iteratorRef, "nowhere") == LE_OK);

        LE_TEST(TestPath(iteratorRef, "/a/path/to/nowhere"));

        le_pathIter_Delete(iteratorRef);
    }

    {
        le_pathIter_Ref_t iteratorRef = le_pathIter_CreateForUnix("");
        LE_TEST(le_pathIter_Append(iteratorRef, "/a//path/to/a///some/../place") == LE_OK);
        LE_TEST(TestPath(iteratorRef, "/a/path/to/a/place"));
        LE_TEST(le_pathIter_IsAbsolute(iteratorRef) == true);

        LE_TEST(le_pathIter_Append(iteratorRef, "../../nowhere") == LE_OK);

        LE_TEST(TestPath(iteratorRef, "/a/path/to/nowhere"));

        le_pathIter_Delete(iteratorRef);
    }

    {
        le_pathIter_Ref_t iteratorRef = le_pathIter_CreateForUnix("/a/b/c");
        LE_TEST(TestPath(iteratorRef, "/a/b/c"));
        LE_TEST(le_pathIter_Append(iteratorRef, "..") == LE_OK);
        LE_TEST(TestPath(iteratorRef, "/a/b"));
        LE_TEST(le_pathIter_IsAbsolute(iteratorRef) == true);
        le_pathIter_Delete(iteratorRef);
    }

    {
        le_pathIter_Ref_t iteratorRef = le_pathIter_CreateForUnix("/a/b/c/");
        LE_TEST(TestPath(iteratorRef, "/a/b/c"));
        LE_TEST(le_pathIter_Append(iteratorRef, "..") == LE_OK);
        LE_TEST(TestPath(iteratorRef, "/a/b"));
        LE_TEST(le_pathIter_IsAbsolute(iteratorRef) == true);
        le_pathIter_Delete(iteratorRef);
    }

    {
        le_pathIter_Ref_t iteratorRef = le_pathIter_CreateForUnix("a/b/c");
        LE_TEST(TestPath(iteratorRef, "a/b/c"));
        LE_TEST(le_pathIter_Append(iteratorRef, "..") == LE_OK);
        LE_TEST(TestPath(iteratorRef, "a/b"));
        LE_TEST(le_pathIter_IsAbsolute(iteratorRef) == false);
        le_pathIter_Delete(iteratorRef);
    }

    {
        le_pathIter_Ref_t iteratorRef = le_pathIter_CreateForUnix("a/b/c/");
        LE_TEST(TestPath(iteratorRef, "a/b/c"));
        LE_TEST(le_pathIter_Append(iteratorRef, "..") == LE_OK);
        LE_TEST(TestPath(iteratorRef, "a/b"));
        LE_TEST(le_pathIter_IsAbsolute(iteratorRef) == false);
        le_pathIter_Delete(iteratorRef);
    }

    {
        le_pathIter_Ref_t iteratorRef = le_pathIter_CreateForUnix("/a");
        LE_TEST(TestPath(iteratorRef, "/a"));
        LE_TEST(le_pathIter_Append(iteratorRef, "..") == LE_OK);
        LE_TEST(TestPath(iteratorRef, "/"));
        LE_TEST(le_pathIter_IsAbsolute(iteratorRef) == true);
        le_pathIter_Delete(iteratorRef);
    }

    {
        le_pathIter_Ref_t iteratorRef = le_pathIter_CreateForUnix("/a/");
        LE_TEST(TestPath(iteratorRef, "/a"));
        LE_TEST(le_pathIter_Append(iteratorRef, "..") == LE_OK);
        LE_TEST(TestPath(iteratorRef, "/"));
        LE_TEST(le_pathIter_IsAbsolute(iteratorRef) == true);
        le_pathIter_Delete(iteratorRef);
    }

    {
        le_pathIter_Ref_t iteratorRef = le_pathIter_CreateForUnix("a");
        LE_TEST(TestPath(iteratorRef, "a"));
        LE_TEST(le_pathIter_Append(iteratorRef, "..") == LE_OK);
        LE_TEST(TestPath(iteratorRef, ""));
        LE_TEST(le_pathIter_IsAbsolute(iteratorRef) == false);
        le_pathIter_Delete(iteratorRef);
    }

    {
        le_pathIter_Ref_t iteratorRef = le_pathIter_CreateForUnix("a/");
        LE_TEST(TestPath(iteratorRef, "a"));
        LE_TEST(le_pathIter_Append(iteratorRef, "..") == LE_OK);
        LE_TEST(TestPath(iteratorRef, ""));
        LE_TEST(le_pathIter_IsAbsolute(iteratorRef) == false);
        le_pathIter_Delete(iteratorRef);
    }
}
示例#7
0
static void TestUnixStyleIterator(void)
{
    LE_INFO("======== Test Unix Style Iterator.");

    static const char* nodes[] = { "a", "path", "to", "some", "end" };
    static const char* nodes2[] = { "a", "b", "c", "d", "e" };

    {
        static const char path[] = "/a/path/to/some/end";

        le_pathIter_Ref_t iteratorRef = le_pathIter_CreateForUnix(path);
        IteratePath(iteratorRef, path, nodes);
        le_pathIter_Delete(iteratorRef);
    }

    {
        static const char path[] = "::a::path::to::some::end";

        le_pathIter_Ref_t iteratorRef = le_pathIter_Create(path, "::", "..", ".");
        IteratePath(iteratorRef, path, nodes);
        le_pathIter_Delete(iteratorRef);
    }

    {
        static const char path[] = "/a/b/c/d/e";

        le_pathIter_Ref_t iteratorRef = le_pathIter_CreateForUnix(path);
        IteratePath(iteratorRef, path, nodes2);
        le_pathIter_Delete(iteratorRef);
    }

    {
        static const char path[] = "::a::b::c::d::e";

        le_pathIter_Ref_t iteratorRef = le_pathIter_Create(path, "::", "..", ".");
        IteratePath(iteratorRef, path, nodes2);
        le_pathIter_Delete(iteratorRef);
    }

    {
        char buffer[LARGE_BUFFER_SIZE] = { 0 };
        le_pathIter_Ref_t iteratorRef = le_pathIter_CreateForUnix("");

        LE_TEST(le_pathIter_GetCurrentNode(iteratorRef,
                                            buffer,
                                            LARGE_BUFFER_SIZE) == LE_NOT_FOUND);
        LE_TEST(strcmp(buffer, "") == 0);
    }

    {
        char buffer[LARGE_BUFFER_SIZE] = { 0 };
        le_pathIter_Ref_t iteratorRef = le_pathIter_CreateForUnix("/");

        le_pathIter_GoToStart(iteratorRef);
        LE_TEST(le_pathIter_GetCurrentNode(iteratorRef,
                                            buffer,
                                            LARGE_BUFFER_SIZE) == LE_NOT_FOUND);
        LE_TEST(strcmp(buffer, "") == 0);

        le_pathIter_GoToEnd(iteratorRef);
        LE_TEST(le_pathIter_GetCurrentNode(iteratorRef,
                                            buffer,
                                            LARGE_BUFFER_SIZE) == LE_NOT_FOUND);
        LE_TEST(strcmp(buffer, "") == 0);
    }

    {
        char buffer[LARGE_BUFFER_SIZE] = { 0 };
        le_pathIter_Ref_t iteratorRef = le_pathIter_CreateForUnix("/some/path/somewhere");

        le_pathIter_GoToStart(iteratorRef);
        LE_TEST(le_pathIter_GetCurrentNode(iteratorRef,
                                            buffer,
                                            LARGE_BUFFER_SIZE) == LE_OK);
        LE_TEST(strcmp(buffer, "some") == 0);

        le_pathIter_GoToEnd(iteratorRef);
        LE_TEST(le_pathIter_GetCurrentNode(iteratorRef,
                                            buffer,
                                            LARGE_BUFFER_SIZE) != LE_NOT_FOUND);
        LE_TEST(strcmp(buffer, "somewhere") == 0);
    }
}
示例#8
0
static void TestConcatenation(void)
{
    LE_INFO("======== Test Concatenations.");

    {
        char buf[100] = "hello/";
        le_result_t result = le_path_Concat("/", buf, sizeof(buf), "there", "how/", "/are",
                                            "/you/", (char*)NULL);
        LE_TEST((result == LE_OK) && (strcmp(buf, "hello/there/how/are/you/") == 0));
    }

    {
        char buf[100] = "/hello//";
        le_result_t result = le_path_Concat("/", buf, sizeof(buf), "there", "how/", "//are", "//you",
                               (char*)NULL);
        LE_TEST((result == LE_OK) && (strcmp(buf, "/hello/there/how/are/you") == 0));
    }

    {
        char buf[100] = "";
        le_result_t result = le_path_Concat("/", buf, sizeof(buf), "hello", "there", "how/", "/are",
                                            "/you/", (char*)NULL);
        LE_TEST((result == LE_OK) && (strcmp(buf, "hello/there/how/are/you/") == 0));
    }

    {
        char buf[100] = "/";
        le_result_t result = le_path_Concat("/", buf, sizeof(buf), "/", "//", (char*)NULL);
        LE_TEST((result == LE_OK) && (strcmp(buf, "/") == 0));
    }

    {
        char buf[100] = "";
        le_result_t result = le_path_Concat("/", buf, sizeof(buf), "/", "//", (char*)NULL);
        LE_TEST((result == LE_OK) && (strcmp(buf, "/") == 0));
    }

    {
        char buf[100] = "__";
        le_result_t result = le_path_Concat("__", buf, sizeof(buf), "__", "____", (char*)NULL);
        LE_TEST((result == LE_OK) && (strcmp(buf, "__") == 0));
    }

    {
        char buf[100] = "";
        le_result_t result = le_path_Concat("__", buf, sizeof(buf), "__", "____", (char*)NULL);
        LE_TEST((result == LE_OK) && (strcmp(buf, "__") == 0));
    }

    {
        char buf[100] = "__hello___";
        le_result_t result = le_path_Concat("__", buf, sizeof(buf), "there", "how__", "_____are",
                                "____you", (char*)NULL);
        LE_TEST((result == LE_OK) && (strcmp(buf, "__hello___there__how___are__you") == 0));
    }

    {
        // Test overflow.
        char buf[35] = "";
        le_result_t result = le_path_Concat("__", buf, sizeof(buf), "__hello___", "there", "how__", "_____are",
                                "____you_doing", (char*)NULL);
        LE_TEST((result == LE_OVERFLOW) && (strcmp(buf, "__hello___there__how___are__you_do") == 0));
    }

    {
        // Test overflow on the separator boundary.
        char buf[35] = "";
        le_result_t result = le_path_Concat("__", buf, sizeof(buf), "__hello___", "there", "how__",
                                "_____are_you_do", "__ing", (char*)NULL);
        LE_TEST((result == LE_OVERFLOW) && (strcmp(buf, "__hello___there__how___are_you_do") == 0));
    }

    {
        // Test no segments.
        char buf[100] = "";
        le_result_t result = le_path_Concat("__", buf, sizeof(buf), (char*)NULL);
        LE_TEST((result == LE_OK) && (strcmp(buf, "") == 0));
    }

    {
        // Test single segment.
        char buf[100] = "";
        le_result_t result = le_path_Concat("__", buf, sizeof(buf), "__h___", (char*)NULL);
        LE_TEST((result == LE_OK) && (strcmp(buf, "__h___") == 0));
    }

    {
        char buf[100] = "/";
        le_result_t result = le_path_Concat("/", buf, sizeof(buf), "h", "", "i/", (char*)NULL);
        LE_TEST((result == LE_OK) && (strcmp(buf, "/h/i/") == 0));
    }

    {
        char buf[100] = "////";
        le_result_t result = le_path_Concat("/", buf, sizeof(buf), "h", "/", "/i/", (char*)NULL);
        LE_TEST((result == LE_OK) && (strcmp(buf, "/h/i/") == 0));
    }

    {
        char buf[100] = "h***";
        le_result_t result = le_path_Concat("***", buf, sizeof(buf), "i", (char*)NULL);
        LE_TEST((result == LE_OK) && (strcmp(buf, "h***i") == 0));
    }

    {
        char buf[100] = "***h***";
        le_result_t result = le_path_Concat("***", buf, sizeof(buf), "***i", (char*)NULL);
        LE_TEST((result == LE_OK) && (strcmp(buf, "***h***i") == 0));
    }
}
示例#9
0
static void ExistAndEmptyTest()
{
    static char pathBuffer[STR_SIZE] = { 0 };
    snprintf(pathBuffer, STR_SIZE, "/%s/existAndEmptyTest/", TestRootDir);

    {
        le_cfg_IteratorRef_t iterRef = le_cfg_CreateWriteTxn(pathBuffer);

        le_cfg_SetEmpty(iterRef, "");
        LE_TEST(le_cfg_IsEmpty(iterRef, "") == true);

        LE_TEST(le_cfg_NodeExists(iterRef, "valueA") == false);
        LE_TEST(le_cfg_NodeExists(iterRef, "valueB") == false);
        LE_TEST(le_cfg_NodeExists(iterRef, "valueC") == false);
        LE_TEST(le_cfg_NodeExists(iterRef, "valueD") == false);

        LE_TEST(le_cfg_IsEmpty(iterRef, "valueA") == true);
        LE_TEST(le_cfg_IsEmpty(iterRef, "valueB") == true);
        LE_TEST(le_cfg_IsEmpty(iterRef, "valueC") == true);
        LE_TEST(le_cfg_IsEmpty(iterRef, "valueD") == true);


        le_cfg_SetString(iterRef, "valueA", "aNewValue");
        le_cfg_SetInt(iterRef, "valueB", 10);
        le_cfg_SetBool(iterRef, "valueC", true);
        le_cfg_SetFloat(iterRef, "valueD", 10.24);

        LE_TEST(le_cfg_NodeExists(iterRef, "valueA") == true);
        LE_TEST(le_cfg_NodeExists(iterRef, "valueB") == true);
        LE_TEST(le_cfg_NodeExists(iterRef, "valueC") == true);
        LE_TEST(le_cfg_NodeExists(iterRef, "valueD") == true);

        LE_TEST(le_cfg_IsEmpty(iterRef, "valueA") == false);
        LE_TEST(le_cfg_IsEmpty(iterRef, "valueB") == false);
        LE_TEST(le_cfg_IsEmpty(iterRef, "valueC") == false);
        LE_TEST(le_cfg_IsEmpty(iterRef, "valueD") == false);

        le_cfg_CommitTxn(iterRef);
    }
}