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
19 * Portions created by the Initial Developer are Copyright (C) 2010
20 * the Initial Developer. All Rights Reserved.
23 * Jim Mathies <jmathies@mozilla.com>
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 /* This tests the margin parsing functionality in nsAttrValue.cpp, which
40 * is accessible via nsIContentUtils, and is used in setting chromemargins
41 * to widget windows. It's located here due to linking issues in the
45 #include "TestHarness.h"
47 #ifndef MOZILLA_INTERNAL_API
48 // some of the includes make use of internal string types
49 #define nsAString_h___
51 #define nsStringFwd_h___
52 #define nsReadableUtils_h___
57 class nsAdoptingString
;
58 class nsAdoptingCString
;
60 template<class T
> class nsReadingIterator
;
64 #include "nsIContentUtils.h"
66 #ifndef MOZILLA_INTERNAL_API
69 #undef nsReadableUtils_h___
81 const bool SHOULD_FAIL
= true;
82 const int SHOULD_PASS
= false;
85 { SHOULD_FAIL
, "", 1, 2, 3, 4 },
86 { SHOULD_FAIL
, "1,0,0,0", 1, 2, 3, 4 },
87 { SHOULD_FAIL
, "1,2,0,0", 1, 2, 3, 4 },
88 { SHOULD_FAIL
, "1,2,3,0", 1, 2, 3, 4 },
89 { SHOULD_FAIL
, "4,3,2,1", 1, 2, 3, 4 },
90 { SHOULD_FAIL
, "azsasdasd", 0, 0, 0, 0 },
91 { SHOULD_FAIL
, ",azsasdasd", 0, 0, 0, 0 },
92 { SHOULD_FAIL
, " ", 1, 2, 3, 4 },
93 { SHOULD_FAIL
, "azsdfsdfsdfsdfsdfsasdasd,asdasdasdasdasdasd,asdadasdasd,asdasdasdasd", 0, 0, 0, 0 },
94 { SHOULD_FAIL
, "as,as,as,as", 0, 0, 0, 0 },
95 { SHOULD_FAIL
, "0,0,0", 0, 0, 0, 0 },
96 { SHOULD_FAIL
, "0,0", 0, 0, 0, 0 },
97 { SHOULD_FAIL
, "4.6,1,1,1", 0, 0, 0, 0 },
98 { SHOULD_FAIL
, ",,,,", 0, 0, 0, 0 },
99 { SHOULD_FAIL
, "1, , , ,", 0, 0, 0, 0 },
100 { SHOULD_FAIL
, "1, , ,", 0, 0, 0, 0 },
101 { SHOULD_FAIL
, "@!@%^&^*()", 1, 2, 3, 4 },
102 { SHOULD_PASS
, "4,3,2,1", 4, 3, 2, 1 },
103 { SHOULD_PASS
, "-4,-3,-2,-1", -4, -3, -2, -1 },
104 { SHOULD_PASS
, "10000,3,2,1", 10000, 3, 2, 1 },
105 { SHOULD_PASS
, "4 , 3 , 2 , 1", 4, 3, 2, 1 },
106 { SHOULD_PASS
, "4, 3 ,2,1", 4, 3, 2, 1 },
107 { SHOULD_FAIL
, "4,3,2,10000000000000 --", 4, 3, 2, 10000000000000 },
108 { SHOULD_PASS
, "4,3,2,1000", 4, 3, 2, 1000 },
109 { SHOULD_PASS
, "2147483647,3,2,1000", 2147483647, 3, 2, 1000 },
110 { SHOULD_PASS
, "2147483647,2147483647,2147483647,2147483647", 2147483647, 2147483647, 2147483647, 2147483647 },
111 { SHOULD_PASS
, "-2147483647,3,2,1000", -2147483647, 3, 2, 1000 },
112 { SHOULD_FAIL
, "2147483648,3,2,1000", 1, 3, 2, 1000 },
113 { 0, nsnull
, 0, 0, 0, 0 }
116 void DoAttrValueTest()
118 nsCOMPtr
<nsIContentUtils
> utils
=
119 do_GetService("@mozilla.org/content/contentutils;1");
122 fail("No nsIContentUtils");
125 bool didFail
= false;
126 while (Data
[++idx
].margins
) {
128 str
.AssignLiteral(Data
[idx
].margins
);
129 nsIntMargin
values(99,99,99,99);
130 bool result
= utils
->ParseIntMarginValue(str
, values
);
132 // if the parse fails
134 if (Data
[idx
].shouldfail
)
136 fail(Data
[idx
].margins
);
142 if (Data
[idx
].shouldfail
) {
143 if (Data
[idx
].top
== values
.top
&&
144 Data
[idx
].right
== values
.right
&&
145 Data
[idx
].bottom
== values
.bottom
&&
146 Data
[idx
].left
== values
.left
) {
148 fail(Data
[idx
].margins
);
153 // good failure, parse failed and that's what we expected.
157 printf("%d==%d %d==%d %d==%d %d==%d\n",
158 Data
[idx
].top
, values
.top
,
159 Data
[idx
].right
, values
.right
,
160 Data
[idx
].bottom
, values
.bottom
,
161 Data
[idx
].left
, values
.left
);
163 if (Data
[idx
].top
== values
.top
&&
164 Data
[idx
].right
== values
.right
&&
165 Data
[idx
].bottom
== values
.bottom
&&
166 Data
[idx
].left
== values
.left
) {
167 // good parse results
171 fail(Data
[idx
].margins
);
179 passed("nsAttrValue margin parsing tests passed.");
182 int main(int argc
, char** argv
)
184 ScopedXPCOM
xpcom("");