Bug 1811840 [wpt PR 38105] - Don't lose the spanner path when relaying out., a=testonly
[gecko.git] / widget / tests / TestChromeMargin.cpp
blob0eed86b208bcd064cda486427da18df542fd062d
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/. */
6 /* This tests the margin parsing functionality in nsAttrValue.cpp, which
7 * is accessible via nsContentUtils, and is used in setting chromemargins
8 * to widget windows. It's located here due to linking issues in the
9 * content directory.
12 /* This test no longer compiles now that we've removed nsIContentUtils (bug
13 * 647273). We need to be internal code in order to include nsContentUtils.h,
14 * but defining MOZILLA_INTERNAL_API is not enough to make us internal.
17 #include "TestHarness.h"
19 #ifndef MOZILLA_INTERNAL_API
20 # error This test needs MOZILLA_INTERNAL_API (see bug 652123)
21 #endif
23 #include "nscore.h"
24 #include "nsContentUtils.h"
25 #include "nsString.h"
27 struct DATA {
28 bool shouldfail;
29 const char* margins;
30 int top;
31 int right;
32 int bottom;
33 int left;
36 const bool SHOULD_FAIL = true;
37 const int SHOULD_PASS = false;
39 const DATA Data[] = {
40 {SHOULD_FAIL, "", 1, 2, 3, 4},
41 {SHOULD_FAIL, "1,0,0,0", 1, 2, 3, 4},
42 {SHOULD_FAIL, "1,2,0,0", 1, 2, 3, 4},
43 {SHOULD_FAIL, "1,2,3,0", 1, 2, 3, 4},
44 {SHOULD_FAIL, "4,3,2,1", 1, 2, 3, 4},
45 {SHOULD_FAIL, "azsasdasd", 0, 0, 0, 0},
46 {SHOULD_FAIL, ",azsasdasd", 0, 0, 0, 0},
47 {SHOULD_FAIL, " ", 1, 2, 3, 4},
48 {SHOULD_FAIL,
49 "azsdfsdfsdfsdfsdfsasdasd,asdasdasdasdasdasd,asdadasdasd,asdasdasdasd", 0,
50 0, 0, 0},
51 {SHOULD_FAIL, "as,as,as,as", 0, 0, 0, 0},
52 {SHOULD_FAIL, "0,0,0", 0, 0, 0, 0},
53 {SHOULD_FAIL, "0,0", 0, 0, 0, 0},
54 {SHOULD_FAIL, "4.6,1,1,1", 0, 0, 0, 0},
55 {SHOULD_FAIL, ",,,,", 0, 0, 0, 0},
56 {SHOULD_FAIL, "1, , , ,", 0, 0, 0, 0},
57 {SHOULD_FAIL, "1, , ,", 0, 0, 0, 0},
58 {SHOULD_FAIL, "@!@%^&^*()", 1, 2, 3, 4},
59 {SHOULD_PASS, "4,3,2,1", 4, 3, 2, 1},
60 {SHOULD_PASS, "-4,-3,-2,-1", -4, -3, -2, -1},
61 {SHOULD_PASS, "10000,3,2,1", 10000, 3, 2, 1},
62 {SHOULD_PASS, "4 , 3 , 2 , 1", 4, 3, 2, 1},
63 {SHOULD_PASS, "4, 3 ,2,1", 4, 3, 2, 1},
64 {SHOULD_FAIL, "4,3,2,10000000000000 --", 4, 3, 2, 10000000000000},
65 {SHOULD_PASS, "4,3,2,1000", 4, 3, 2, 1000},
66 {SHOULD_PASS, "2147483647,3,2,1000", 2147483647, 3, 2, 1000},
67 {SHOULD_PASS, "2147483647,2147483647,2147483647,2147483647", 2147483647,
68 2147483647, 2147483647, 2147483647},
69 {SHOULD_PASS, "-2147483647,3,2,1000", -2147483647, 3, 2, 1000},
70 {SHOULD_FAIL, "2147483648,3,2,1000", 1, 3, 2, 1000},
71 {0, nullptr, 0, 0, 0, 0}};
73 void DoAttrValueTest() {
74 int idx = -1;
75 bool didFail = false;
76 while (Data[++idx].margins) {
77 nsAutoString str;
78 str.AssignLiteral(Data[idx].margins);
79 nsIntMargin values(99, 99, 99, 99);
80 bool result = nsContentUtils::ParseIntMarginValue(str, values);
82 // if the parse fails
83 if (!result) {
84 if (Data[idx].shouldfail) continue;
85 fail(Data[idx].margins);
86 didFail = true;
87 printf("*1\n");
88 continue;
91 if (Data[idx].shouldfail) {
92 if (Data[idx].top == values.top && Data[idx].right == values.right &&
93 Data[idx].bottom == values.bottom && Data[idx].left == values.left) {
94 // not likely
95 fail(Data[idx].margins);
96 didFail = true;
97 printf("*2\n");
98 continue;
100 // good failure, parse failed and that's what we expected.
101 continue;
103 #if 0
104 printf("%d==%d %d==%d %d==%d %d==%d\n",
105 Data[idx].top, values.top,
106 Data[idx].right, values.right,
107 Data[idx].bottom, values.bottom,
108 Data[idx].left, values.left);
109 #endif
110 if (Data[idx].top == values.top && Data[idx].right == values.right &&
111 Data[idx].bottom == values.bottom && Data[idx].left == values.left) {
112 // good parse results
113 continue;
114 } else {
115 fail(Data[idx].margins);
116 didFail = true;
117 printf("*3\n");
118 continue;
122 if (!didFail) passed("nsAttrValue margin parsing tests passed.");
125 int main(int argc, char** argv) {
126 ScopedXPCOM xpcom("");
127 if (xpcom.failed()) return 1;
128 DoAttrValueTest();
129 return 0;