aboutsummaryrefslogtreecommitdiff
path: root/test/identifier.c
blob: abbcdac866f8814d31376bcf3fa782afdc497ae2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

#include "kpl_test.h"

KPL_TEST(c_string_to_identifier) {
    const char *string = "aA0_t4_12w0abcdefghijklmnop456789Z";
    kpl_identifier identifier;
    KPL_ASSERT(kpl_identifier_encode(&identifier, string, strlen(string)), "should encode");
    char buffer[100] = {};
    const int32_t offset = 10;
    kpl_identifier_decode(&identifier, buffer + offset);
    KPL_ASSERT(strcmp(string, buffer + offset) == 0, "should decode to same string");
}

KPL_TEST(identifier_compare) {
    const char *string_a = "abc123456789", *string_b = "abc123456789", *string_c = "abd123456789";
    kpl_identifier identifier_a, identifier_b, identifier_c;
    KPL_ASSERT(kpl_identifier_encode(&identifier_a, string_a, strlen(string_a)), "should encode");
    KPL_ASSERT(kpl_identifier_encode(&identifier_b, string_b, strlen(string_b)), "should encode");
    KPL_ASSERT(kpl_identifier_encode(&identifier_c, string_c, strlen(string_c)), "should encode");
    KPL_ASSERT(kpl_identifier_compare(&identifier_a, &identifier_b) == 0, "should be 0");
    int32_t compare_value = strcmp(string_b, string_c);
    KPL_ASSERT(kpl_identifier_compare(&identifier_b, &identifier_c) == compare_value, "should equal strcmp");
    KPL_ASSERT(kpl_identifier_equal(&identifier_a, &identifier_b), "should be equal");
}