Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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 | |
michael@0 | 6 | /* This tests the margin parsing functionality in nsAttrValue.cpp, which |
michael@0 | 7 | * is accessible via nsContentUtils, and is used in setting chromemargins |
michael@0 | 8 | * to widget windows. It's located here due to linking issues in the |
michael@0 | 9 | * content directory. |
michael@0 | 10 | */ |
michael@0 | 11 | |
michael@0 | 12 | /* This test no longer compiles now that we've removed nsIContentUtils (bug |
michael@0 | 13 | * 647273). We need to be internal code in order to include nsContentUtils.h, |
michael@0 | 14 | * but defining MOZILLA_INTERNAL_API is not enough to make us internal. |
michael@0 | 15 | */ |
michael@0 | 16 | |
michael@0 | 17 | #include "TestHarness.h" |
michael@0 | 18 | |
michael@0 | 19 | #ifndef MOZILLA_INTERNAL_API |
michael@0 | 20 | // some of the includes make use of internal string types |
michael@0 | 21 | #define nsAString_h___ |
michael@0 | 22 | #define nsString_h___ |
michael@0 | 23 | #define nsStringFwd_h___ |
michael@0 | 24 | #define nsReadableUtils_h___ |
michael@0 | 25 | class nsACString; |
michael@0 | 26 | class nsAString; |
michael@0 | 27 | class nsAFlatString; |
michael@0 | 28 | class nsAFlatCString; |
michael@0 | 29 | class nsAdoptingString; |
michael@0 | 30 | class nsAdoptingCString; |
michael@0 | 31 | class nsXPIDLString; |
michael@0 | 32 | template<class T> class nsReadingIterator; |
michael@0 | 33 | #endif |
michael@0 | 34 | |
michael@0 | 35 | #include "nscore.h" |
michael@0 | 36 | #include "nsContentUtils.h" |
michael@0 | 37 | |
michael@0 | 38 | #ifndef MOZILLA_INTERNAL_API |
michael@0 | 39 | #undef nsString_h___ |
michael@0 | 40 | #undef nsAString_h___ |
michael@0 | 41 | #undef nsReadableUtils_h___ |
michael@0 | 42 | #endif |
michael@0 | 43 | |
michael@0 | 44 | struct DATA { |
michael@0 | 45 | bool shouldfail; |
michael@0 | 46 | const char* margins; |
michael@0 | 47 | int top; |
michael@0 | 48 | int right; |
michael@0 | 49 | int bottom; |
michael@0 | 50 | int left; |
michael@0 | 51 | }; |
michael@0 | 52 | |
michael@0 | 53 | const bool SHOULD_FAIL = true; |
michael@0 | 54 | const int SHOULD_PASS = false; |
michael@0 | 55 | |
michael@0 | 56 | const DATA Data[] = { |
michael@0 | 57 | { SHOULD_FAIL, "", 1, 2, 3, 4 }, |
michael@0 | 58 | { SHOULD_FAIL, "1,0,0,0", 1, 2, 3, 4 }, |
michael@0 | 59 | { SHOULD_FAIL, "1,2,0,0", 1, 2, 3, 4 }, |
michael@0 | 60 | { SHOULD_FAIL, "1,2,3,0", 1, 2, 3, 4 }, |
michael@0 | 61 | { SHOULD_FAIL, "4,3,2,1", 1, 2, 3, 4 }, |
michael@0 | 62 | { SHOULD_FAIL, "azsasdasd", 0, 0, 0, 0 }, |
michael@0 | 63 | { SHOULD_FAIL, ",azsasdasd", 0, 0, 0, 0 }, |
michael@0 | 64 | { SHOULD_FAIL, " ", 1, 2, 3, 4 }, |
michael@0 | 65 | { SHOULD_FAIL, "azsdfsdfsdfsdfsdfsasdasd,asdasdasdasdasdasd,asdadasdasd,asdasdasdasd", 0, 0, 0, 0 }, |
michael@0 | 66 | { SHOULD_FAIL, "as,as,as,as", 0, 0, 0, 0 }, |
michael@0 | 67 | { SHOULD_FAIL, "0,0,0", 0, 0, 0, 0 }, |
michael@0 | 68 | { SHOULD_FAIL, "0,0", 0, 0, 0, 0 }, |
michael@0 | 69 | { SHOULD_FAIL, "4.6,1,1,1", 0, 0, 0, 0 }, |
michael@0 | 70 | { SHOULD_FAIL, ",,,,", 0, 0, 0, 0 }, |
michael@0 | 71 | { SHOULD_FAIL, "1, , , ,", 0, 0, 0, 0 }, |
michael@0 | 72 | { SHOULD_FAIL, "1, , ,", 0, 0, 0, 0 }, |
michael@0 | 73 | { SHOULD_FAIL, "@!@%^&^*()", 1, 2, 3, 4 }, |
michael@0 | 74 | { SHOULD_PASS, "4,3,2,1", 4, 3, 2, 1 }, |
michael@0 | 75 | { SHOULD_PASS, "-4,-3,-2,-1", -4, -3, -2, -1 }, |
michael@0 | 76 | { SHOULD_PASS, "10000,3,2,1", 10000, 3, 2, 1 }, |
michael@0 | 77 | { SHOULD_PASS, "4 , 3 , 2 , 1", 4, 3, 2, 1 }, |
michael@0 | 78 | { SHOULD_PASS, "4, 3 ,2,1", 4, 3, 2, 1 }, |
michael@0 | 79 | { SHOULD_FAIL, "4,3,2,10000000000000 --", 4, 3, 2, 10000000000000 }, |
michael@0 | 80 | { SHOULD_PASS, "4,3,2,1000", 4, 3, 2, 1000 }, |
michael@0 | 81 | { SHOULD_PASS, "2147483647,3,2,1000", 2147483647, 3, 2, 1000 }, |
michael@0 | 82 | { SHOULD_PASS, "2147483647,2147483647,2147483647,2147483647", 2147483647, 2147483647, 2147483647, 2147483647 }, |
michael@0 | 83 | { SHOULD_PASS, "-2147483647,3,2,1000", -2147483647, 3, 2, 1000 }, |
michael@0 | 84 | { SHOULD_FAIL, "2147483648,3,2,1000", 1, 3, 2, 1000 }, |
michael@0 | 85 | { 0, nullptr, 0, 0, 0, 0 } |
michael@0 | 86 | }; |
michael@0 | 87 | |
michael@0 | 88 | void DoAttrValueTest() |
michael@0 | 89 | { |
michael@0 | 90 | int idx = -1; |
michael@0 | 91 | bool didFail = false; |
michael@0 | 92 | while (Data[++idx].margins) { |
michael@0 | 93 | nsAutoString str; |
michael@0 | 94 | str.AssignLiteral(Data[idx].margins); |
michael@0 | 95 | nsIntMargin values(99,99,99,99); |
michael@0 | 96 | bool result = nsContentUtils::ParseIntMarginValue(str, values); |
michael@0 | 97 | |
michael@0 | 98 | // if the parse fails |
michael@0 | 99 | if (!result) { |
michael@0 | 100 | if (Data[idx].shouldfail) |
michael@0 | 101 | continue; |
michael@0 | 102 | fail(Data[idx].margins); |
michael@0 | 103 | didFail = true; |
michael@0 | 104 | printf("*1\n"); |
michael@0 | 105 | continue; |
michael@0 | 106 | } |
michael@0 | 107 | |
michael@0 | 108 | if (Data[idx].shouldfail) { |
michael@0 | 109 | if (Data[idx].top == values.top && |
michael@0 | 110 | Data[idx].right == values.right && |
michael@0 | 111 | Data[idx].bottom == values.bottom && |
michael@0 | 112 | Data[idx].left == values.left) { |
michael@0 | 113 | // not likely |
michael@0 | 114 | fail(Data[idx].margins); |
michael@0 | 115 | didFail = true; |
michael@0 | 116 | printf("*2\n"); |
michael@0 | 117 | continue; |
michael@0 | 118 | } |
michael@0 | 119 | // good failure, parse failed and that's what we expected. |
michael@0 | 120 | continue; |
michael@0 | 121 | } |
michael@0 | 122 | #if 0 |
michael@0 | 123 | printf("%d==%d %d==%d %d==%d %d==%d\n", |
michael@0 | 124 | Data[idx].top, values.top, |
michael@0 | 125 | Data[idx].right, values.right, |
michael@0 | 126 | Data[idx].bottom, values.bottom, |
michael@0 | 127 | Data[idx].left, values.left); |
michael@0 | 128 | #endif |
michael@0 | 129 | if (Data[idx].top == values.top && |
michael@0 | 130 | Data[idx].right == values.right && |
michael@0 | 131 | Data[idx].bottom == values.bottom && |
michael@0 | 132 | Data[idx].left == values.left) { |
michael@0 | 133 | // good parse results |
michael@0 | 134 | continue; |
michael@0 | 135 | } |
michael@0 | 136 | else { |
michael@0 | 137 | fail(Data[idx].margins); |
michael@0 | 138 | didFail = true; |
michael@0 | 139 | printf("*3\n"); |
michael@0 | 140 | continue; |
michael@0 | 141 | } |
michael@0 | 142 | } |
michael@0 | 143 | |
michael@0 | 144 | if (!didFail) |
michael@0 | 145 | passed("nsAttrValue margin parsing tests passed."); |
michael@0 | 146 | } |
michael@0 | 147 | |
michael@0 | 148 | int main(int argc, char** argv) |
michael@0 | 149 | { |
michael@0 | 150 | ScopedXPCOM xpcom(""); |
michael@0 | 151 | if (xpcom.failed()) |
michael@0 | 152 | return 1; |
michael@0 | 153 | DoAttrValueTest(); |
michael@0 | 154 | return 0; |
michael@0 | 155 | } |