1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 // No output means test passed.
42 #include "nsColorNames.h"
46 static const char* kJunkNames
[] = {
55 int main(int argc
, char** argv
)
61 // Everything appears to assert if we don't do this first...
62 nsColorNames::AddRefTable();
64 // First make sure we can find all of the tags that are supposed to
65 // be in the table. Futz with the case to make sure any case will
68 index
= eColorName_UNKNOWN
;
69 while (PRInt32(index
) < (PRInt32 (eColorName_COUNT
) - 1)) {
70 // Lookup color by name and make sure it has the right id
71 index
= nsColorName(PRInt32(index
) + 1);
72 nsCString
tagName(nsColorNames::GetStringValue(index
));
73 if (tagName
.IsEmpty()) {
74 printf("bug: tagName for nsColorNames::GetStringValue(%d) is ''\n", index
);
79 id
= nsColorNames::LookupName(NS_ConvertASCIItoUTF16(tagName
));
80 if (id
== eColorName_UNKNOWN
) {
81 printf("bug: can't find '%s'\n", tagName
.get());
85 printf("bug: name='%s' id=%d index=%d\n", tagName
.get(), id
, index
);
89 // fiddle with the case to make sure we can still find it
90 tagName
.SetCharAt(tagName
.CharAt(0) - 32, 0);
91 id
= nsColorNames::LookupName(NS_ConvertASCIItoUTF16(tagName
));
92 if (id
== eColorName_UNKNOWN
) {
93 printf("bug: can't find '%s'\n", tagName
.get());
97 printf("bug: name='%s' id=%d index=%d\n", tagName
.get(), id
, index
);
101 // Check that color lookup by name gets the right rgb value
103 if (!NS_ColorNameToRGB(NS_ConvertASCIItoUTF16(tagName
), &rgb
)) {
104 printf("bug: name='%s' didn't NS_ColorNameToRGB\n", tagName
.get());
107 if (nsColorNames::kColors
[index
] != rgb
) {
108 printf("bug: name='%s' ColorNameToRGB=%x kColors[%d]=%x\n",
109 tagName
.get(), rgb
, nsColorNames::kColors
[index
],
110 nsColorNames::kColors
[index
]);
114 // Check that parsing an RGB value in hex gets the right values
115 PRUint8 r
= NS_GET_R(rgb
);
116 PRUint8 g
= NS_GET_G(rgb
);
117 PRUint8 b
= NS_GET_B(rgb
);
119 PR_snprintf(cbuf
, sizeof(cbuf
), "%02x%02x%02x", r
, g
, b
);
121 if (!NS_HexToRGB(NS_ConvertASCIItoUTF16(cbuf
), &hexrgb
)) {
122 printf("bug: hex conversion to color of '%s' failed\n", cbuf
);
126 printf("bug: rgb=%x hexrgb=%x\n", rgb
, hexrgb
);
131 // Now make sure we don't find some garbage
132 for (int i
= 0; i
< (int) (sizeof(kJunkNames
) / sizeof(const char*)); i
++) {
133 const char* tag
= kJunkNames
[i
];
134 id
= nsColorNames::LookupName(NS_ConvertASCIItoUTF16(tag
));
135 if (id
> eColorName_UNKNOWN
) {
136 printf("bug: found '%s'\n", tag
? tag
: "(null)");