layout/style/test/TestCSSPropertyLookup.cpp

Wed, 31 Dec 2014 13:27:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 13:27:57 +0100
branch
TOR_BUG_3246
changeset 6
8bccb770b82d
permissions
-rw-r--r--

Ignore runtime configuration files generated during quality assurance.

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

mercurial