File size: 3,242 Bytes
6baed57
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include "unity/unity.h"
#include <libxml/HTMLparser.h>
#include <string.h>
#include <stdlib.h>

/* External wrapper for the static function under test, provided in the module */
extern int test_htmlCompareStartClose(const void *vkey, const void *member);

/* Local struct with the same field layout (two const char* pointers)
   as expected by the comparator. We avoid redefining internal types. */
typedef struct {
    const char *oldTag;
    const char *newTag;
} TestEntry;

static int call_compare(const char *keyOld, const char *keyNew,
                        const char *entOld, const char *entNew) {
    TestEntry key = { keyOld, keyNew };
    TestEntry ent = { entOld, entNew };
    return test_htmlCompareStartClose((const void *)&key, (const void *)&ent);
}

void setUp(void) {
    /* Setup code here, or leave empty */
}

void tearDown(void) {
    /* Cleanup code here, or leave empty */
}

void test_htmlCompareStartClose_equal_old_and_new(void) {
    int ret = call_compare("div", "span", "div", "span");
    TEST_ASSERT_EQUAL_INT(0, ret);
}

void test_htmlCompareStartClose_different_old_less(void) {
    /* "a" < "b" */
    int ret = call_compare("a", "x", "b", "x");
    TEST_ASSERT_TRUE(ret < 0);
}

void test_htmlCompareStartClose_different_old_greater(void) {
    /* "span" > "div" */
    int ret = call_compare("span", "x", "div", "x");
    TEST_ASSERT_TRUE(ret > 0);
}

void test_htmlCompareStartClose_same_old_different_new_less(void) {
    /* old equal; new "a" < "b" */
    int ret = call_compare("p", "a", "p", "b");
    TEST_ASSERT_TRUE(ret < 0);
}

void test_htmlCompareStartClose_same_old_different_new_greater(void) {
    /* old equal; new "z" > "y" */
    int ret = call_compare("p", "z", "p", "y");
    TEST_ASSERT_TRUE(ret > 0);
}

void test_htmlCompareStartClose_prefix_oldtag_less(void) {
    /* "div" < "diva" because shorter prefix compares less */
    int ret = call_compare("div", "x", "diva", "x");
    TEST_ASSERT_TRUE(ret < 0);
}

void test_htmlCompareStartClose_prefix_newtag_less(void) {
    /* old equal; "div" < "diva" on newTag */
    int ret = call_compare("tag", "div", "tag", "diva");
    TEST_ASSERT_TRUE(ret < 0);
}

void test_htmlCompareStartClose_case_sensitivity_in_oldtag(void) {
    /* 'D' (0x44) < 'd' (0x64); so "Div" < "div" */
    int ret = call_compare("Div", "x", "div", "x");
    TEST_ASSERT_TRUE(ret < 0);
}

void test_htmlCompareStartClose_case_sensitivity_in_newtag(void) {
    /* old equal; 'A' < 'a'; so "Anchor" < "anchor" */
    int ret = call_compare("tag", "Anchor", "tag", "anchor");
    TEST_ASSERT_TRUE(ret < 0);
}

int main(void) {
    UNITY_BEGIN();
    RUN_TEST(test_htmlCompareStartClose_equal_old_and_new);
    RUN_TEST(test_htmlCompareStartClose_different_old_less);
    RUN_TEST(test_htmlCompareStartClose_different_old_greater);
    RUN_TEST(test_htmlCompareStartClose_same_old_different_new_less);
    RUN_TEST(test_htmlCompareStartClose_same_old_different_new_greater);
    RUN_TEST(test_htmlCompareStartClose_prefix_oldtag_less);
    RUN_TEST(test_htmlCompareStartClose_prefix_newtag_less);
    RUN_TEST(test_htmlCompareStartClose_case_sensitivity_in_oldtag);
    RUN_TEST(test_htmlCompareStartClose_case_sensitivity_in_newtag);
    return UNITY_END();
}