Changeset 41893 in webkit for trunk/JavaScriptCore/API
- Timestamp:
- Mar 21, 2009, 6:40:22 PM (16 years ago)
- Location:
- trunk/JavaScriptCore/API/tests
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/API/tests/testapi.c
r41846 r41893 42 42 43 43 static JSGlobalContextRef context = 0; 44 44 static int failed = 0; 45 45 static void assertEqualsAsBoolean(JSValueRef value, bool expectedValue) 46 46 { 47 if (JSValueToBoolean(context, value) != expectedValue) 47 if (JSValueToBoolean(context, value) != expectedValue) { 48 48 fprintf(stderr, "assertEqualsAsBoolean failed: %p, %d\n", value, expectedValue); 49 failed = 1; 50 } 49 51 } 50 52 … … 56 58 // causing a build break with -Wshorten-64-to-32 enabled. The issue is known by the appropriate team. 57 59 // After that's resolved, we can remove these casts 58 if (number != expectedValue && !(isnan((float)number) && isnan((float)expectedValue))) 60 if (number != expectedValue && !(isnan((float)number) && isnan((float)expectedValue))) { 59 61 fprintf(stderr, "assertEqualsAsNumber failed: %p, %lf\n", value, expectedValue); 62 failed = 1; 63 } 60 64 } 61 65 … … 69 73 70 74 unsigned i; 71 for (i = 0; jsBuffer[i]; i++) 72 if (jsBuffer[i] != expectedValue[i]) 75 for (i = 0; jsBuffer[i]; i++) { 76 if (jsBuffer[i] != expectedValue[i]) { 73 77 fprintf(stderr, "assertEqualsAsUTF8String failed at character %d: %c(%d) != %c(%d)\n", i, jsBuffer[i], jsBuffer[i], expectedValue[i], expectedValue[i]); 74 75 if (jsSize < strlen(jsBuffer) + 1) 78 failed = 1; 79 } 80 } 81 82 if (jsSize < strlen(jsBuffer) + 1) { 76 83 fprintf(stderr, "assertEqualsAsUTF8String failed: jsSize was too small\n"); 84 failed = 1; 85 } 77 86 78 87 free(jsBuffer); … … 95 104 CFRelease(expectedValueAsCFString); 96 105 97 if (memcmp(jsBuffer, cfBuffer, cfLength * sizeof(UniChar)) != 0) 106 if (memcmp(jsBuffer, cfBuffer, cfLength * sizeof(UniChar)) != 0) { 98 107 fprintf(stderr, "assertEqualsAsCharactersPtr failed: jsBuffer != cfBuffer\n"); 99 100 if (jsLength != (size_t)cfLength) 108 failed = 1; 109 } 110 111 if (jsLength != (size_t)cfLength) { 101 112 fprintf(stderr, "assertEqualsAsCharactersPtr failed: jsLength(%ld) != cfLength(%ld)\n", jsLength, cfLength); 102 113 failed = 1; 114 } 115 103 116 free(cfBuffer); 104 117 JSStringRelease(valueAsString); … … 847 860 848 861 string = JSValueToStringCopy(context, function, NULL); 849 assertEqualsAsUTF8String(JSValueMakeString(context, string), "function foo(foo) { return foo;}");862 assertEqualsAsUTF8String(JSValueMakeString(context, string), "function foo(foo) {\nreturn foo;\n}"); 850 863 JSStringRelease(string); 851 864 … … 1008 1021 printf("PASS: Infinite prototype chain does not occur.\n"); 1009 1022 1023 if (failed) { 1024 printf("FAIL: Some tests failed.\n"); 1025 return 1; 1026 } 1027 1010 1028 printf("PASS: Program exited normally.\n"); 1011 1029 return 0; -
trunk/JavaScriptCore/API/tests/testapi.js
r35900 r41893 23 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 24 */ 25 var failed = false; 26 function pass(msg) 27 { 28 print("PASS: " + msg, "green"); 29 } 30 31 function fail(msg) 32 { 33 print("FAIL: " + msg, "red"); 34 failed = true; 35 } 25 36 26 37 function shouldBe(a, b) … … 34 45 35 46 if (evalA == b || isNaN(evalA) && typeof evalA == 'number' && isNaN(b) && typeof b == 'number') 36 p rint("PASS: " + a + " should be " + b + " and is.", "green");47 pass(a + " should be " + b + " and is."); 37 48 else 38 print("__FAIL__: " + a + " should be " + b + " but instead is " + evalA + ".", "red");49 fail(a + " should be " + b + " but instead is " + evalA + "."); 39 50 } 40 51 41 52 function shouldThrow(a) 42 53 { 43 var result = "__FAIL__: " + a + " did not throw an exception.";44 45 54 var evalA; 46 55 try { 47 56 eval(a); 48 57 } catch(e) { 49 result = "PASS: " + a + " threw: " + e; 58 pass(a + " threw: " + e); 59 return; 50 60 } 51 52 print(result);61 62 fail(a + " did not throw an exception."); 53 63 } 54 64 … … 83 93 foundRegularType = true; 84 94 } 85 print(foundMyPropertyName 86 ? "PASS: MyObject.myPropertyName was enumerated" 87 : "__FAIL__: MyObject.myPropertyName was not enumerated"); 88 print(foundRegularType 89 ? "PASS: MyObject.regularType was enumerated" 90 : "__FAIL__: MyObject.regularType was not enumerated"); 95 96 if (foundMyPropertyName) 97 pass("MyObject.myPropertyName was enumerated"); 98 else 99 fail("MyObject.myPropertyName was not enumerated"); 100 101 if (foundRegularType) 102 pass("MyObject.regularType was enumerated"); 103 else 104 fail("MyObject.regularType was not enumerated"); 91 105 92 106 myObject = new MyObject(); … … 131 145 shouldBe("derived.derivedOnly = 0", 2) 132 146 shouldBe("derived.protoDup = 0", 2); 147 148 if (failed) 149 throw "Some tests failed"; 150
Note:
See TracChangeset
for help on using the changeset viewer.