|
| 1 | +#include <string.h> |
| 2 | + |
| 3 | +#include <epicsUnitTest.h> |
| 4 | +#include <testMain.h> |
| 5 | + |
| 6 | +#include "caster.h" |
| 7 | + |
| 8 | +void* epicsRtemsFSImage; |
| 9 | + |
| 10 | +static void testLog(void* arg, struct _caster_t* self) |
| 11 | +{ |
| 12 | + testDiag("ERR %s", self->lastmsg); |
| 13 | +} |
| 14 | + |
| 15 | +static void testAddExcludePatternX(void) |
| 16 | +{ |
| 17 | + int i = 0; |
| 18 | + caster_t caster; |
| 19 | + casterInit(&caster); |
| 20 | + caster.onmsg = &testLog; |
| 21 | + |
| 22 | + int argc; |
| 23 | + char *argvlist[5]; |
| 24 | + argvlist[0] = "addReccasterExcludePattern"; |
| 25 | + |
| 26 | + char *expectedPatterns[] = |
| 27 | + { |
| 28 | + "*_", |
| 29 | + "*__", |
| 30 | + "*:Intrnl:*", |
| 31 | + "*_internal", |
| 32 | + "*exclude_me" |
| 33 | + }; |
| 34 | + int expectedNumPatterns = 0; |
| 35 | + |
| 36 | + testDiag("Testing addReccasterExcludePattern with one good env"); |
| 37 | + argvlist[1] = "*_"; |
| 38 | + argc = 2; |
| 39 | + testOk1(caster.exclude_patterns.count==expectedNumPatterns); |
| 40 | + addReccasterExcludePattern(&caster, argc, argvlist); |
| 41 | + expectedNumPatterns++; |
| 42 | + testOk1(caster.exclude_patterns.count==expectedNumPatterns); |
| 43 | + ELLNODE *cur; |
| 44 | + cur = ellFirst(&caster.exclude_patterns); |
| 45 | + while (cur != NULL) { |
| 46 | + string_list_t *temp = (string_list_t *)cur; |
| 47 | + testOk1(strcmp(temp->item_str, expectedPatterns[i]) == 0); |
| 48 | + i++; |
| 49 | + cur = ellNext(cur); |
| 50 | + } |
| 51 | + |
| 52 | + testDiag("Testing addReccasterExcludePattern with two more patterns"); |
| 53 | + argvlist[1] = "*__"; |
| 54 | + argvlist[2] = "*:Intrnl:*"; |
| 55 | + argc = 3; |
| 56 | + i = 0; |
| 57 | + testOk1(caster.exclude_patterns.count==expectedNumPatterns); |
| 58 | + addReccasterExcludePattern(&caster, argc, argvlist); |
| 59 | + expectedNumPatterns += 2; |
| 60 | + testOk1(caster.exclude_patterns.count==expectedNumPatterns); |
| 61 | + cur = ellFirst(&caster.exclude_patterns); |
| 62 | + while (cur != NULL) { |
| 63 | + string_list_t *temp = (string_list_t *)cur; |
| 64 | + testOk1(strcmp(temp->item_str, expectedPatterns[i]) == 0); |
| 65 | + i++; |
| 66 | + cur = ellNext(cur); |
| 67 | + } |
| 68 | + |
| 69 | + testDiag("Testing addReccasterExcludePattern with a duplicate pattern"); |
| 70 | + argvlist[1] = "*_"; |
| 71 | + argc = 2; |
| 72 | + i = 0; |
| 73 | + testOk1(caster.exclude_patterns.count==expectedNumPatterns); |
| 74 | + addReccasterExcludePattern(&caster, argc, argvlist); |
| 75 | + testOk1(caster.exclude_patterns.count==expectedNumPatterns); |
| 76 | + cur = ellFirst(&caster.exclude_patterns); |
| 77 | + while (cur != NULL) { |
| 78 | + string_list_t *temp = (string_list_t *)cur; |
| 79 | + testOk1(strcmp(temp->item_str, expectedPatterns[i]) == 0); |
| 80 | + i++; |
| 81 | + cur = ellNext(cur); |
| 82 | + } |
| 83 | + |
| 84 | + testDiag("Testing addReccasterExcludePattern with a new and a duplicate"); |
| 85 | + argvlist[1] = "*_internal"; |
| 86 | + argvlist[2] = "*__"; |
| 87 | + argc = 3; |
| 88 | + i = 0; |
| 89 | + testOk1(caster.exclude_patterns.count==expectedNumPatterns); |
| 90 | + addReccasterExcludePattern(&caster, argc, argvlist); |
| 91 | + expectedNumPatterns++; |
| 92 | + testOk1(caster.exclude_patterns.count==expectedNumPatterns); |
| 93 | + cur = ellFirst(&caster.exclude_patterns); |
| 94 | + while (cur != NULL) { |
| 95 | + string_list_t *temp = (string_list_t *)cur; |
| 96 | + testOk1(strcmp(temp->item_str, expectedPatterns[i]) == 0); |
| 97 | + i++; |
| 98 | + cur = ellNext(cur); |
| 99 | + } |
| 100 | + |
| 101 | + testDiag("Testing addReccasterExcludePattern with two of the same pattern"); |
| 102 | + argvlist[1] = "*exclude_me"; |
| 103 | + argvlist[2] = "*exclude_me"; |
| 104 | + argc = 3; |
| 105 | + i = 0; |
| 106 | + testOk1(caster.exclude_patterns.count==expectedNumPatterns); |
| 107 | + addReccasterExcludePattern(&caster, argc, argvlist); |
| 108 | + expectedNumPatterns++; |
| 109 | + testOk1(caster.exclude_patterns.count==expectedNumPatterns); |
| 110 | + cur = ellFirst(&caster.exclude_patterns); |
| 111 | + while (cur != NULL) { |
| 112 | + string_list_t *temp = (string_list_t *)cur; |
| 113 | + testOk1(strcmp(temp->item_str, expectedPatterns[i]) == 0); |
| 114 | + i++; |
| 115 | + cur = ellNext(cur); |
| 116 | + } |
| 117 | + |
| 118 | + testDiag("Testing addReccasterExcludePattern with duplicates in argv and exclude pattern list"); |
| 119 | + argvlist[1] = "*__"; |
| 120 | + argvlist[2] = "*__"; |
| 121 | + argc = 3; |
| 122 | + i = 0; |
| 123 | + testOk1(caster.exclude_patterns.count==expectedNumPatterns); |
| 124 | + addReccasterExcludePattern(&caster, argc, argvlist); |
| 125 | + testOk1(caster.exclude_patterns.count==expectedNumPatterns); |
| 126 | + cur = ellFirst(&caster.exclude_patterns); |
| 127 | + while (cur != NULL) { |
| 128 | + string_list_t *temp = (string_list_t *)cur; |
| 129 | + testOk1(strcmp(temp->item_str, expectedPatterns[i]) == 0); |
| 130 | + i++; |
| 131 | + cur = ellNext(cur); |
| 132 | + } |
| 133 | + |
| 134 | + epicsEventSignal(caster.shutdownEvent); |
| 135 | + casterShutdown(&caster); |
| 136 | +} |
| 137 | + |
| 138 | +static void testAddExcludePatternBadInput() |
| 139 | +{ |
| 140 | + caster_t caster; |
| 141 | + casterInit(&caster); |
| 142 | + caster.onmsg = &testLog; |
| 143 | + |
| 144 | + int argc; |
| 145 | + char *argvlist[2]; |
| 146 | + argvlist[0] = "addReccasterExcludePattern"; |
| 147 | + |
| 148 | + testDiag("Testing addReccasterExcludePattern with no arguments"); |
| 149 | + argc = 1; |
| 150 | + testOk1(caster.exclude_patterns.count==0); |
| 151 | + addReccasterExcludePattern(&caster, argc, argvlist); |
| 152 | + testOk1(caster.exclude_patterns.count==0); |
| 153 | + |
| 154 | + testDiag("Testing addReccasterExcludePattern with empty string argument"); |
| 155 | + argvlist[1] = ""; |
| 156 | + argc = 2; |
| 157 | + testOk1(caster.exclude_patterns.count==0); |
| 158 | + addReccasterExcludePattern(&caster, argc, argvlist); |
| 159 | + testOk1(caster.exclude_patterns.count==0); |
| 160 | + |
| 161 | + epicsEventSignal(caster.shutdownEvent); |
| 162 | + casterShutdown(&caster); |
| 163 | +} |
| 164 | + |
| 165 | +MAIN(testAddExcludePattern) |
| 166 | +{ |
| 167 | + testPlan(37); |
| 168 | + osiSockAttach(); |
| 169 | + testAddExcludePatternX(); |
| 170 | + testAddExcludePatternBadInput(); |
| 171 | + osiSockRelease(); |
| 172 | + return testDone(); |
| 173 | +} |
0 commit comments