Wed, 31 Dec 2014 13:27:57 +0100
Ignore runtime configuration files generated during quality assurance.
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include <stdio.h>
6 #include "plstr.h"
7 #include "nsCSSProps.h"
8 #include "nsCSSKeywords.h"
9 #include "nsString.h"
10 #include "nsXPCOM.h"
12 static const char* const kJunkNames[] = {
13 nullptr,
14 "",
15 "123",
16 "backgroundz",
17 "zzzzzz",
18 "#@$&@#*@*$@$#"
19 };
21 static bool
22 TestProps()
23 {
24 bool success = true;
25 nsCSSProperty id;
26 nsCSSProperty index;
28 // Everything appears to assert if we don't do this first...
29 nsCSSProps::AddRefTable();
31 // First make sure we can find all of the tags that are supposed to
32 // be in the table. Futz with the case to make sure any case will
33 // work
34 extern const char* const kCSSRawProperties[];
35 const char*const* et = &kCSSRawProperties[0];
36 const char*const* end = &kCSSRawProperties[eCSSProperty_COUNT];
37 index = eCSSProperty_UNKNOWN;
38 while (et < end) {
39 char tagName[100];
40 PL_strcpy(tagName, *et);
41 index = nsCSSProperty(int32_t(index) + 1);
43 id = nsCSSProps::LookupProperty(nsCString(tagName),
44 nsCSSProps::eIgnoreEnabledState);
45 if (id == eCSSProperty_UNKNOWN) {
46 printf("bug: can't find '%s'\n", tagName);
47 success = false;
48 }
49 if (id != index) {
50 printf("bug: name='%s' id=%d index=%d\n", tagName, id, index);
51 success = false;
52 }
54 // fiddle with the case to make sure we can still find it
55 if (('a' <= tagName[0]) && (tagName[0] <= 'z')) {
56 tagName[0] = tagName[0] - 32;
57 }
58 id = nsCSSProps::LookupProperty(NS_ConvertASCIItoUTF16(tagName),
59 nsCSSProps::eIgnoreEnabledState);
60 if (id < 0) {
61 printf("bug: can't find '%s'\n", tagName);
62 success = false;
63 }
64 if (index != id) {
65 printf("bug: name='%s' id=%d index=%d\n", tagName, id, index);
66 success = false;
67 }
68 et++;
69 }
71 // Now make sure we don't find some garbage
72 for (int i = 0; i < (int) (sizeof(kJunkNames) / sizeof(const char*)); i++) {
73 const char* const tag = kJunkNames[i];
74 id = nsCSSProps::LookupProperty(nsAutoCString(tag),
75 nsCSSProps::eIgnoreEnabledState);
76 if (id >= 0) {
77 printf("bug: found '%s'\n", tag ? tag : "(null)");
78 success = false;
79 }
80 }
82 nsCSSProps::ReleaseTable();
83 return success;
84 }
86 bool
87 TestKeywords()
88 {
89 nsCSSKeywords::AddRefTable();
91 bool success = true;
92 nsCSSKeyword id;
93 nsCSSKeyword index;
95 extern const char* const kCSSRawKeywords[];
97 // First make sure we can find all of the tags that are supposed to
98 // be in the table. Futz with the case to make sure any case will
99 // work
100 const char*const* et = &kCSSRawKeywords[0];
101 const char*const* end = &kCSSRawKeywords[eCSSKeyword_COUNT - 1];
102 index = eCSSKeyword_UNKNOWN;
103 while (et < end) {
104 char tagName[512];
105 char* underscore = &(tagName[0]);
107 PL_strcpy(tagName, *et);
108 while (*underscore) {
109 if (*underscore == '_') {
110 *underscore = '-';
111 }
112 underscore++;
113 }
114 index = nsCSSKeyword(int32_t(index) + 1);
116 id = nsCSSKeywords::LookupKeyword(nsCString(tagName));
117 if (id <= eCSSKeyword_UNKNOWN) {
118 printf("bug: can't find '%s'\n", tagName);
119 success = false;
120 }
121 if (id != index) {
122 printf("bug: name='%s' id=%d index=%d\n", tagName, id, index);
123 success = false;
124 }
126 // fiddle with the case to make sure we can still find it
127 if (('a' <= tagName[0]) && (tagName[0] <= 'z')) {
128 tagName[0] = tagName[0] - 32;
129 }
130 id = nsCSSKeywords::LookupKeyword(nsCString(tagName));
131 if (id <= eCSSKeyword_UNKNOWN) {
132 printf("bug: can't find '%s'\n", tagName);
133 success = false;
134 }
135 if (id != index) {
136 printf("bug: name='%s' id=%d index=%d\n", tagName, id, index);
137 success = false;
138 }
139 et++;
140 }
142 // Now make sure we don't find some garbage
143 for (int i = 0; i < (int) (sizeof(kJunkNames) / sizeof(const char*)); i++) {
144 const char* const tag = kJunkNames[i];
145 id = nsCSSKeywords::LookupKeyword(nsAutoCString(tag));
146 if (eCSSKeyword_UNKNOWN < id) {
147 printf("bug: found '%s'\n", tag ? tag : "(null)");
148 success = false;
149 }
150 }
152 nsCSSKeywords::ReleaseTable();
153 return success;
154 }
156 int
157 main(void)
158 {
159 nsresult rv = NS_InitXPCOM2(nullptr, nullptr, nullptr);
160 NS_ENSURE_SUCCESS(rv, 2);
162 bool testOK = true;
163 testOK &= TestProps();
164 testOK &= TestKeywords();
166 rv = NS_ShutdownXPCOM(nullptr);
167 NS_ENSURE_SUCCESS(rv, 2);
169 return testOK ? 0 : 1;
170 }