How to use testSpec method in Cypress

Best JavaScript code snippet using cypress

osc-tests.js

Source:osc-tests.js Github

copy

Full Screen

1/*global QUnit, equal, deepEqual, osc, test, ok*/2(function () {3 "use strict";4 /*************5 * Utilities *6 *************/7 var stringToDataView = function (str) {8 var arr = new Uint8Array(str.length),9 dv = new DataView(arr.buffer);10 for (var i = 0; i < str.length; i++) {11 dv.setUint8(i, str.charCodeAt(i));12 }13 return dv;14 };15 var numbersToDataView = function (nums, type, width) {16 var arr = new ArrayBuffer(nums.length * width),17 setter = "set" + type[0].toUpperCase() + type.substring(1),18 dv = new DataView(arr);19 for (var i = 0, offset = 0; i < nums.length; i++, offset = i * width) {20 var num = nums[i];21 dv[setter](offset, num, false);22 }23 return dv;24 };25 var arrayEqual = function (actual, expected, msg) {26 equal(actual.length, expected.length, "The array should be the expected length.");27 for (var i = 0; i < actual.length; i++) {28 var actualVal = actual[i],29 expectedVal = expected[i];30 if (typeof actualVal === "object" && typeof actualVal.length === "number") {31 arrayEqual(actualVal, expectedVal, msg);32 } else {33 deepEqual(actualVal, expectedVal, msg);34 }35 }36 };37 var roundTo = function (val, numDecimals) {38 return typeof val === "number" ? parseFloat(val.toFixed(numDecimals)) : val;39 };40 var equalRoundedTo = function (actual, expected, numDecimals, msg) {41 var actualRounded = roundTo(actual, numDecimals),42 expectedRounded = roundTo(expected, numDecimals);43 equal(actualRounded, expectedRounded, msg + "\nUnrounded value was: " + expected);44 };45 var roundArrayValues = function (arr, numDecimals) {46 var togo = [];47 for (var i = 0; i < arr.length; i++) {48 var val = arr[i];49 var type = typeof val;50 togo[i] = type === "object" ? roundAllValues(val, numDecimals) : roundTo(val, numDecimals);51 }52 return togo;53 };54 var arrayEqualRounded = function (actual, expected, numDecimals, msg) {55 var actualRounded = roundArrayValues(actual, numDecimals),56 expectedRounded = roundArrayValues(expected, numDecimals);57 arrayEqual(actualRounded, expectedRounded, msg + "\nActual unrounded array: " + actual);58 };59 var roundAllValues = function (obj, numDecimals) {60 var togo = {};61 for (var key in obj) {62 var val = obj[key];63 if (osc.isArray(val)) {64 togo[key] = roundArrayValues(val, numDecimals);65 } else if (typeof val === "object") {66 togo[key] = roundAllValues(val, numDecimals);67 } else {68 togo[key] = roundTo(val, numDecimals);69 }70 }71 return togo;72 };73 var roundedDeepEqual = function (actual, expected, numDecimals, msg) {74 var roundedActual = roundAllValues(actual, numDecimals),75 roundedExpected = roundAllValues(expected, numDecimals);76 deepEqual(roundedActual, roundedExpected, msg = "\nUnrounded actual object was: " +77 JSON.stringify(roundedActual));78 };79 /************80 * Strings *81 ************/82 QUnit.module("Strings");83 var testReadString = function (testSpec) {84 var offsetState = testSpec.offsetState || {85 idx: 086 };87 test("readString " + testSpec.name, function () {88 var expected = testSpec.rawString,89 dv = stringToDataView(testSpec.paddedString),90 actual = osc.readString(dv, offsetState);91 equal(actual, expected, "The string should have been read correctly.");92 equal(offsetState.idx, testSpec.paddedString.length,93 "The offset state should correctly reflect the null padding of the OSC string.");94 });95 };96 var testWriteString = function (testSpec) {97 test("writeString " + testSpec.name, function () {98 var expectedDV = stringToDataView(testSpec.paddedString),99 expected = new Uint8Array(expectedDV.buffer),100 actualBuf = osc.writeString(testSpec.rawString),101 actual = new Uint8Array(actualBuf);102 arrayEqual(actual, expected, "The string should have been written correctly.");103 ok(actualBuf instanceof Uint8Array, "The returned value should be a Uint8Array.");104 });105 };106 var stringTestSpecs = [107 {108 name: "four character (eight byte) string",109 paddedString: "data\u0000\u0000\u0000\u0000",110 rawString: "data"111 },112 {113 name: "three character (four byte) string",114 paddedString: "OSC\u0000",115 rawString: "OSC"116 }117 ];118 var stringTests = function (testSpecs) {119 for (var i = 0; i < testSpecs.length; i++) {120 var testSpec = testSpecs[i];121 testReadString(testSpec);122 testWriteString(testSpec);123 }124 };125 stringTests(stringTestSpecs);126 /***********127 * Numbers *128 ***********/129 QUnit.module("Numbers");130 var typeTesters = {131 "int32": {132 dataViewConverter: numbersToDataView,133 reader: osc.readInt32,134 width: 4135 },136 "float32": {137 dataViewConverter: numbersToDataView,138 reader: osc.readFloat32,139 width: 4140 }141 };142 var testReadPrimitive = function (type, arr, expected, offsetState) {143 offsetState = offsetState || {144 idx: 0145 };146 var testMap = typeTesters[type],147 dv = testMap.dataViewConverter(arr, type, testMap.width),148 expectedOffsetIdx = offsetState.idx + testMap.width,149 actual = testMap.reader(dv, offsetState);150 equalRoundedTo(actual, expected, 5, "The correct value should have been read.");151 equal(offsetState.idx, expectedOffsetIdx, "The offset state should have been updated appropriately.");152 };153 var makeReadPrimitiveTester = function (type, testSpec) {154 return function () {155 testReadPrimitive(type, testSpec.nums, testSpec.expected, {156 idx: testSpec.offset157 });158 };159 };160 var readPrimitiveTests = function (testSpecs) {161 for (var type in testSpecs) {162 var specsForType = testSpecs[type];163 for (var i = 0; i < specsForType.length; i++) {164 var spec = specsForType[i];165 test(spec.name, makeReadPrimitiveTester(type, spec));166 }167 }168 };169 var readPrimitiveTestSpecs = {170 "int32": [171 {172 name: "Read an int32 value in the middle of a byte array",173 nums: new Int32Array([1, -1, 2000000, -600]),174 expected: 2000000,175 offset: 8176 },177 {178 name: "Read an in32 value at the end of a byte array",179 nums: new Int32Array([1, -1, 2000000, -600]),180 expected: -600,181 offset: 12182 },183 {184 name: "Read an in32 value at the beginning of a byte array",185 nums: new Int32Array([1, -1, 2000000, -600]),186 expected: 1,187 offset: 0188 }189 ],190 "float32": [191 {192 name: "Read a float32 value in the middle of a byte array",193 nums: new Float32Array([42.42, 0.00001, 10000000000.00000001, 27]),194 expected: 0.00001,195 offset: 4196 },197 {198 name: "Read a float32 value in at the end of a byte array",199 nums: new Float32Array([42.42, 0.00001, 10000000000.00000001, 27]),200 expected: 27,201 offset: 12202 },203 {204 name: "Read a float32 value in at the beginning of a byte array",205 nums: new Float32Array([42.42, 0.00001, 10000000000.00000001, 27]),206 expected: 42.42,207 offset: 0208 }209 ]210 };211 readPrimitiveTests(readPrimitiveTestSpecs);212 var testWritePrimitive = function (testSpec) {213 test(testSpec.writer + " " + testSpec.name, function () {214 var expected = testSpec.expected,215 outBuf = new ArrayBuffer(expected.buffer.byteLength),216 dv = new DataView(outBuf),217 actual = osc[testSpec.writer](testSpec.val, dv, testSpec.offset);218 arrayEqual(actual, expected, "The value should have been written to the output buffer.");219 });220 };221 var writePrimitiveTestSpecs = [222 {223 writer: "writeInt32",224 name: "simple value",225 val: 32,226 expected: new Uint8Array([0, 0, 0, 32])227 },228 {229 writer: "writeInt32",230 name: "negative 32 bit value",231 val: -1,232 expected: new Uint8Array([255, 255, 255, 255])233 },234 {235 writer: "writeInt32",236 name: "with offset",237 val: -1,238 offset: 4,239 expected: new Uint8Array([0, 0, 0, 0, 255, 255, 255, 255])240 },241 {242 writer: "writeFloat32",243 name: "simple value",244 val: 42.42,245 expected: new Uint8Array([66, 41, 174, 20])246 },247 {248 writer: "writeFloat32",249 name: "negative value",250 val: -3.14159,251 expected: new Uint8Array([192, 73, 15, 208])252 },253 {254 writer: "writeFloat32",255 name: "simple value with offset",256 val: 1,257 offset: 12,258 expected: new Uint8Array([259 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 63, 128, 0, 0, 0, 0, 0, 0260 ])261 }262 ];263 var writePrimitiveTests = function (testSpecs) {264 for (var i = 0; i < testSpecs.length; i++) {265 var testSpec = testSpecs[i];266 testWritePrimitive(testSpec);267 }268 };269 writePrimitiveTests(writePrimitiveTestSpecs);270 /*********271 * Blobs *272 *********/273 QUnit.module("Blobs");274 var oscBlobOctets = [275 0, 0, 0, 3, // Length 3276 0x63, 0x61, 0x74, 0 // raw bytes277 ];278 var oscBlob = new Uint8Array(oscBlobOctets);279 var oscBlobOctetsWithExtra = oscBlobOctets.concat([1, 2, 3, 4]); // some random stuff afterwards.280 var oscExtraBlob = new Uint8Array(oscBlobOctetsWithExtra);281 var rawData = new Uint8Array([282 0x63, 0x61, 0x74283 ]);284 test("readBlob", function () {285 var dv = new DataView(oscExtraBlob.buffer);286 var expected = rawData;287 var offsetState = {288 idx: 0289 };290 var actual = osc.readBlob(dv, offsetState);291 arrayEqual(actual, expected, "The blob should be returned as-is.");292 ok(actual instanceof Uint8Array, "The blob should be returned as a Uint8Array.");293 equal(offsetState.idx, 8, "The offset state should have been updated correctly.");294 });295 test("writeBlob", function () {296 var expected = oscBlob,297 actual = osc.writeBlob(rawData);298 arrayEqual(new Uint8Array(actual), expected,299 "The data should have been packed into a correctly-formatted OSC blob.");300 ok(actual instanceof Uint8Array, "The written blob should be a Uint8Array");301 });302 /*************303 * Time Tags *304 *************/305 QUnit.module("Time Tags");306 var equalWithinTolerance = function (actual, expected, tolerance, msg) {307 var max = expected + tolerance,308 min = expected - tolerance;309 ok(actual <= max, "The value should be no greater than " + tolerance + ". " + msg);310 ok(actual >= min, "The value should be no less than " + tolerance + ". " + msg);311 };312 var testReadTimeTag = function (testSpec) {313 test("Read time tag " + testSpec.name, function () {314 var expected = testSpec.timeTag,315 dv = new DataView(testSpec.timeTagBytes.buffer);316 var actual = osc.readTimeTag(dv, {317 idx: 0318 });319 if (expected.raw[0] === 0 && expected.raw[1] === 1) {320 var tolerance = 150;321 equalWithinTolerance(actual.native, expected.native,322 tolerance, "The native time tag should be within " + tolerance +323 "ms of expected. Difference was: " + (actual.native - expected.native) + "ms.");324 deepEqual(actual.raw, expected.raw, "The raw time should match identically.");325 } else {326 deepEqual(actual, expected, "The date should have be read correctly.");327 }328 });329 };330 var testWriteTimeTag = function (testSpec) {331 test("Write time tag " + testSpec.name, function () {332 var expected = testSpec.timeTagBytes,333 actual = osc.writeTimeTag(testSpec.timeTag);334 arrayEqual(actual, expected, "The raw time tag should have have been written correctly.");335 });336 };337 var timeTagTestSpecs = [338 {339 name: "with seconds only",340 // May 4, 2014 at 0:00:00 UTC.341 timeTagBytes: new Uint8Array([342 215, 15, 243, 112,343 0, 0, 0, 0344 ]),345 timeTag: {346 raw: [3608146800, 0],347 native: 1399158000 * 1000348 }349 },350 {351 name: "with fractions of a second",352 // Half a second past midnight on Sunday May 4, 2014.353 timeTagBytes: new Uint8Array([354 // [3608146800, 2147483648]355 215, 15, 243, 112,356 128, 0, 0 , 0357 ]),358 timeTag: {359 raw: [3608146800, 4294967296 / 2],360 native: (1399158000 * 1000) + 500361 }362 },363 {364 name: "one fraction of a second (i.e. now in OSC time tag-speak)",365 timeTagBytes: new Uint8Array([366 0, 0, 0, 0,367 0, 0, 0, 1368 ]),369 timeTag: {370 raw: [0, 1],371 native: Date.now()372 }373 }374 ];375 var timeTagTests = function (testSpecs) {376 for (var i = 0; i < testSpecs.length; i++) {377 var testSpec = testSpecs[i];378 testReadTimeTag(testSpec);379 testWriteTimeTag(testSpec);380 }381 };382 timeTagTests(timeTagTestSpecs);383 test("Write native-only time tag.", function () {384 var testSpec = timeTagTestSpecs[1],385 expected = testSpec.timeTagBytes,386 timeTag = {387 native: testSpec.timeTag.native388 };389 var actual = osc.writeTimeTag(timeTag);390 arrayEqual(actual, expected,391 "A time tag with no raw value (only a native value) should be written correctly.");392 });393 var testTimeTag = function (actual, expectedJSTime, tolerance) {394 if (tolerance === undefined) {395 tolerance = 1000; // NTP fractional values.396 }397 // Convert the JS time to NTP time.398 var expected = osc.jsToNTPTime(expectedJSTime),399 max = expected[1] + tolerance,400 min = expected[1] - tolerance;401 equal(actual.raw[0], expected[0], "The generated timestamp should be accurate to the second.");402 ok(actual.raw[1] <= max, "The generated timestamp should be no greater than " + tolerance +403 " NTP fractions of a second from expected.");404 ok(actual.raw[1] >= min, "The generated timestamp should be no less than " + tolerance +405 " NTP fractions of a second from expected.");406 };407 test("osc.timeTag now", function () {408 var actual = osc.timeTag();409 testTimeTag(actual, Date.now());410 actual = osc.timeTag(0);411 testTimeTag(actual, Date.now());412 });413 test("osc.timeTag future", function () {414 var actual = osc.timeTag(10.5),415 expected = Date.now() + 10500;416 testTimeTag(actual, expected);417 actual = osc.timeTag(0.1);418 expected = Date.now() + 100;419 testTimeTag(actual, expected);420 });421 test("osc.timeTag past", function () {422 var actual = osc.timeTag(-1000),423 expected = Date.now() - 1000000;424 testTimeTag(actual, expected);425 actual = osc.timeTag(-0.01);426 expected = Date.now() - 10;427 });428 /**********************************************429 * Read Type-Only Arguments (e.g. T, F, N, I) *430 **********************************************/431 QUnit.module("Type-Only Arguments");432 test("Type-only arguments", function () {433 var offsetState = {434 idx: 27435 };436 var bool = osc.readTrue();437 equal(bool, true, "readTrue() should return a true value");438 equal(offsetState.idx, 27, "The offset state should not have been changed.");439 bool = osc.readFalse();440 equal(bool, false, "readFalse() should return false value");441 equal(offsetState.idx, 27, "The offset state should not have been changed.");442 var nully = osc.readNull();443 equal(nully, null, "readNull() should return null.");444 equal(offsetState.idx, 27, "The offset state should not have been changed.");445 var imp = osc.readImpulse();446 equal(imp, 1.0, "readImpulse() should return 1.0.");447 equal(offsetState.idx, 27, "The offset state should not have been changed.");448 });449 /******************450 * Read Arguments *451 ******************/452 QUnit.module("readArguments()");453 var testArguments = function (testSpec) {454 //rawArgBuffer, expected, roundToDecimals, offsetState455 //testSpec.rawArgBuffer, testSpec.expected, testSpec.roundToDecimals456 test(testSpec.name, function () {457 var offsetState = {458 idx: 0459 };460 var expected = testSpec.expected,461 dv = new DataView(testSpec.rawArgBuffer.buffer),462 actual = osc.readArguments(dv, false, offsetState);463 if (testSpec.roundToDecimals !== undefined) {464 arrayEqualRounded(actual, expected, testSpec.roundToDecimals, offsetState);465 } else {466 arrayEqual(actual, expected,467 "The returned arguments should have the correct values in the correct order.");468 }469 });470 };471 var argumentTestSpecs = [472 {473 name: "single argument",474 rawArgBuffer: new Uint8Array([475 // ",f"476 0x2c, 0x66, 0, 0,477 // 440478 0x43, 0xdc, 0 , 0479 ]),480 expected: [440]481 },482 {483 name: "blob and float",484 rawArgBuffer: new Uint8Array([485 // ",bf"486 0x2c, 0x62, 0x66, 0,487 // 3488 0, 0, 0, 3,489 // blob490 0x63, 0x61, 0x74, 0,491 // 440492 0x43, 0xdc, 0 , 0493 ]),494 expected: [new Uint8Array([495 0x63, 0x61, 0x74,496 ]), 440]497 },498 {499 name: "multiple arguments of the same type",500 rawArgBuffer: new Uint8Array([501 //",iisff"502 0x2c, 0x69, 0x69, 0x73,503 0x66, 0x66, 0, 0,504 // 1000505 0, 0, 0x3, 0xe8,506 // -1507 0xff, 0xff, 0xff, 0xff,508 // "hello"509 0x68, 0x65, 0x6c, 0x6c,510 0x6f, 0, 0, 0,511 // 1.1234512 0x3f, 0x9d, 0xf3, 0xb6,513 // 5.678514 0x40, 0xb5, 0xb2, 0x2d515 ]),516 expected: [1000, -1, "hello", 1.234, 5.678],517 roundToDecimals: 3518 },519 {520 name: "colours",521 rawArgBuffer: new Uint8Array([522 // ,rr523 44, 114, 114, 0,524 // White color525 255, 255, 255, 0,526 // Green color rba(255, 255, 255, 0.3)527 0, 255, 0, 77,528 // Some junk529 255, 128, 64, 12530 ]),531 expected: [{r: 255, g: 255, b: 255, a: 0}, {r: 0, g: 255, b: 0, a: 77 / 255}]532 },533 {534 name: "arrays",535 rawArgBuffer: new Uint8Array([536 // ,s[rr]i537 44, 115, 91, 114,538 114, 93, 105, 0,539 // "cat",540 99, 97, 116, 0,541 // White color542 255, 255, 255, 0,543 // Green color rba(255, 255, 255, 0.3)544 0, 255, 0, 77,545 // #42546 0, 0, 0, 42547 ]),548 expected: [549 "cat",550 [{r: 255, g: 255, b: 255, a: 0}, {r: 0, g: 255, b: 0, a: 77 / 255}],551 42552 ]553 },554 {555 name: "every type of arg",556 rawArgBuffer: new Uint8Array([557 // ",ifsSbtTFNI[ii]dcrm"558 //44 105 102 115 83 98 116 84 70 78 73 91 105 105 93 100 99 114 109559 44, 105, 102, 115,560 83, 98, 116, 84,561 70, 78, 73, 91,562 105, 105, 93, 100,563 99, 114, 109, 0,564 // i: 1565 0, 0, 0, 1,566 //f: 1.234567 0x3f, 0x9d, 0xf3, 0xb6,568 // s: "cat"569 99, 97, 116, 0,570 //"\cat"571 92, 99, 97, 116,572 0, 0, 0, 0,573 // blob{3, [255, 255, 0]}574 0, 0, 0, 3,575 255, 255, 0, 0,576 // t: {raw: [2208988800, 0], native: 0}577 131, 170, 126, 128,578 0, 0, 0, 0,579 // [ii]: [42, 47]580 0, 0, 0, 42,581 0, 0, 0, 47,582 // d: 2.1583 0x40, 0x00, 0xCC, 0xCC,584 0xCC, 0xCC, 0xCC, 0xCD,585 // c: "z"586 0, 0, 0, 122,587 // {r: 128, g: 64, b: 192, a: 1.0},588 128, 64, 192, 255,589 // m: [1, 144, 69, 101] // port id 1 , note on chan 1, C3, velocity 101]590 1, 144, 69, 101591 ]),592 // ",ifsSbtTFNI[ii]dcrm"593 expected: [594 1,595 1.234,596 "cat",597 "\\cat",598 new Uint8Array([255, 255, 0]),599 {600 raw: [2208988800, 0],601 native: 0602 },603 true,604 false,605 null,606 1.0,607 [608 42,609 47610 ],611 2.1,612 "z",613 {614 r: 128,615 g: 64,616 b: 192,617 a: 1.0618 },619 new Uint8Array([1, 144, 69, 101])620 ],621 roundToDecimals: 3622 }623 ];624 var readArgumentsTests = function (testSpecs) {625 for (var i = 0; i < testSpecs.length; i++) {626 var testSpec = testSpecs[i];627 testArguments(testSpec);628 }629 };630 readArgumentsTests(argumentTestSpecs);631 /************632 * Messages *633 ************/634 QUnit.module("Messages");635 var testReadMessage = function (testSpec) {636 testSpec.offsetState = testSpec.offsetState || {637 idx: 0638 };639 test("readMessage " + testSpec.name, function () {640 var expected = testSpec.message,641 dv = new DataView(testSpec.oscMessageBuffer.buffer),642 actual = osc.readMessage(dv, testSpec.options, testSpec.offsetState),643 msg = "The returned message object should match the raw message data.";644 if (testSpec.roundToDecimals !== undefined) {645 roundedDeepEqual(actual, expected, testSpec.roundToDecimals, msg);646 } else {647 deepEqual(actual, expected, msg);648 }649 });650 };651 var testWriteMessage = function (testSpec) {652 test("writeMessage " + testSpec.name, function () {653 var expected = testSpec.oscMessageBuffer,654 actual = osc.writeMessage(testSpec.message, testSpec.options);655 arrayEqual(actual, expected, "The message should have been written correctly.");656 });657 };658 var messageTestSpecs = [659 {660 name: "without type metadata",661 // "/oscillator/4/frequency" | ",f" | 440662 oscMessageBuffer: new Uint8Array([663 0x2f, 0x6f, 0x73, 0x63,664 0x69, 0x6c, 0x6c, 0x61,665 0x74, 0x6f, 0x72, 0x2f,666 0x34, 0x2f, 0x66, 0x72,667 0x65, 0x71, 0x75, 0x65,668 0x6e, 0x63, 0x79, 0,669 0x2c, 0x66, 0, 0,670 0x43, 0xdc, 0, 0671 ]),672 message: {673 address: "/oscillator/4/frequency",674 args: 440675 }676 },677 {678 name: "with type metadata",679 oscMessageBuffer: new Uint8Array([680 // "/foo" | ",iisTff" | 1000, -1, "hello", 1.1234, 5.678681 0x2f, 0x66, 0x6f, 0x6f, // "/foo"682 0, 0, 0, 0, // padding683 0x2c, 0x69, 0x69, 0x73, // ,iis684 0x54, 0x66, 0x66, 0, // Tff padding685 0, 0, 0x3, 0xe8,686 0xff, 0xff, 0xff, 0xff,687 0x68, 0x65, 0x6c, 0x6c,688 0x6f, 0, 0, 0,689 0x3f, 0x9d, 0xf3, 0xb6,690 0x40, 0xb5, 0xb2, 0x2d691 ]),692 message: {693 address: "/foo",694 args: [695 {696 type: "i",697 value: 1000698 },699 {700 type: "i",701 value: -1702 },703 {704 type: "s",705 value: "hello"706 },707 {708 type: "T",709 value: true710 },711 {712 type: "f",713 value: 1.234714 },715 {716 type: "f",717 value: 5.678718 }719 ]720 },721 roundToDecimals: 3,722 options: {723 metadata: true724 }725 }726 ];727 var testMessages = function (testSpecs) {728 for (var i = 0; i < testSpecs.length; i++) {729 var testSpec = testSpecs[i];730 testReadMessage(testSpec);731 testWriteMessage(testSpec);732 }733 };734 testMessages(messageTestSpecs);735 test("gh-17", function () {736 var msg = {737 address: "/sl/1/down",738 args: [739 {740 type: "f", // OSC type tag string741 value: 444.4742 }743 ]744 };745 var encoded = osc.writeMessage(msg);746 var decoded = osc.readMessage(encoded, {747 metadata: true748 });749 roundedDeepEqual(decoded, msg, "The message should have been encoded and decoded correctly.");750 });751 /***********752 * Bundles *753 ***********/754 QUnit.module("Bundles");755 var testReadBundle = function (testSpec) {756 test("readBundle " + testSpec.name, function () {757 var expected = testSpec.bundle,758 dv = new DataView(testSpec.bytes.buffer),759 offsetState = {760 idx: 0761 };762 var actual = osc.readBundle(dv, testSpec.options, offsetState);763 roundedDeepEqual(actual, expected,764 "The bundle should have been read correctly.");765 equal(offsetState.idx, dv.byteLength,766 "The offset state should have been adjusted correctly.");767 });768 };769 var testWriteBundle = function (testSpec) {770 test("writeBundle " + testSpec.name, function () {771 var expected = testSpec.bytes,772 actual = osc.writeBundle(testSpec.bundle, testSpec.options);773 arrayEqual(actual, expected,774 "The bundle should have been written correctly.");775 });776 };777 var bundleTestSpecs = [778 {779 name: "with nested bundles.",780 bytes: new Uint8Array([781 // "#bundle"782 35, 98, 117, 110,783 100, 108, 101, 0,784 // timetag [3608492400, 0]785 215, 21, 57, 112,786 0, 0, 0, 0,787 // first packet:788 // size 24 bytes789 0, 0, 0, 24,790 // "/cat/meow/freq"791 47, 99, 97, 116,792 47, 109, 101, 111,793 119, 47, 102, 114,794 101, 113, 0, 0,795 //,f796 44, 102, 0, 0,797 // 222.2798 67, 94, 51, 51,799 // second packet:800 // size 44 bytes801 0, 0, 0, 48,802 // "#bundle"803 35, 98, 117, 110,804 100, 108, 101, 0,805 // timetag [3608406000, 0]806 215, 19, 231, 240,807 0, 0, 0, 0,808 // packet 2.a:809 // size 28 bytes810 0, 0, 0, 28,811 // "/hamster/wheel/freq"812 47, 104, 97, 109,813 115, 116, 101, 114,814 47, 119, 104, 101,815 101, 108, 47, 102,816 114, 101, 113, 0,817 // type tag ,i818 44, 105, 0, 0,819 // 100820 0, 0, 0, 100,821 // third packet:822 // size 32 bytes823 0, 0, 0, 32,824 // "/fish/burble/amp"825 47, 102, 105, 115,826 104, 47, 98, 117,827 114, 98, 108, 101,828 47, 97, 109, 112,829 0, 0, 0, 0,830 // type tag ,fs831 44, 102, 115, 0,832 // -6, "dB"833 192, 192, 0, 0,834 100, 66, 0, 0835 ]),836 bundle: {837 timeTag: {838 // 215, 21, 57, 112 | 0, 0, 0, 0839 raw: [3608492400, 0],840 native: 1399503600000841 },842 packets: [843 {844 // 47 99 97 116 | 47 109 101 111 | 119 47 102 114 | 101 113 0 0845 address: "/cat/meow/freq",846 // type tag: ,f: 44 102 0 0 | values: 67 94 51 51847 args: [848 {849 type: "f",850 value: 222.2,851 }852 ]853 },854 {855 timeTag: {856 // 215 19 231 240 | 0 0 0 0857 raw: [3608406000, 0],858 native: 1399417200000859 },860 packets: [861 {862 // 47 104 97 109 | 115 116 101 114 | 47 119 104 101 | 101 108 47 102 | 114 101 113 0863 address: "/hamster/wheel/freq",864 // type tag ,i: 44 105 0 0 | values: 66 200 0 0865 args: [866 {867 type: "i",868 value: 100869 }870 ]871 }872 ]873 },874 {875 // 47 102 105 115 | 104 47 98 117 | 114 98 108 101 | 47 97 109 112 | 0 0 0 0876 address: "/fish/burble/amp",877 // type tag ,fs: 44 102 115 0 | values: 255 255 255 250, 100 66 0 0878 args: [879 {880 type: "f",881 value: -6882 },883 {884 type: "s",885 value: "dB"886 }887 ]888 }889 ]890 },891 options: {892 metadata: true893 }894 }895 ];896 var testBundles = function (testSpecs) {897 for (var i = 0; i < testSpecs.length; i++) {898 var testSpec = testSpecs[i];899 testReadBundle(testSpec);900 testWriteBundle(testSpec);901 }902 };903 testBundles(bundleTestSpecs);...

Full Screen

Full Screen

es3fSamplerObjectTests.js

Source:es3fSamplerObjectTests.js Github

copy

Full Screen

1/*-------------------------------------------------------------------------2 * drawElements Quality Program OpenGL ES Utilities3 * ------------------------------------------------4 *5 * Copyright 2014 The Android Open Source Project6 *7 * Licensed under the Apache License, Version 2.0 (the 'License');8 * you may not use this file except in compliance with the License.9 * You may obtain a copy of the License at10 *11 * http://www.apache.org/licenses/LICENSE-2.012 *13 * Unless required by applicable law or agreed to in writing, software14 * distributed under the License is distributed on an 'AS IS' BASIS,15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.16 * See the License for the specific language governing permissions and17 * limitations under the License.18 *19 */20'use strict';21goog.provide('functional.gles3.es3fSamplerObjectTests');22goog.require('framework.common.tcuTestCase');23goog.require('modules.shared.glsSamplerObjectTest');24goog.scope(function() {25var es3fSamplerObjectTests = functional.gles3.es3fSamplerObjectTests;26var tcuTestCase = framework.common.tcuTestCase;27var glsSamplerObjectTest = modules.shared.glsSamplerObjectTest;28 /** @type {WebGL2RenderingContext} */ var gl;29 // TODO: implement glsSamplerObjectTest and validate constructors30 es3fSamplerObjectTests.init = function() {31 var testGroup = tcuTestCase.runner.testCases;32 /** @type {Array<glsSamplerObjectTest.TestSpec>} */ var simpleTestCases = [33 new glsSamplerObjectTest.TestSpec('diff_wrap_t', 'Different gl.TEXTURE_WRAP_T', gl.TEXTURE_2D,34 new glsSamplerObjectTest.SamplingState(gl.NEAREST, gl.NEAREST, gl.MIRRORED_REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, 1000.0),35 new glsSamplerObjectTest.SamplingState(gl.NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, 1000.0)36 ),37 new glsSamplerObjectTest.TestSpec('diff_wrap_s', 'Different gl.TEXTURE_WRAP_S', gl.TEXTURE_2D,38 new glsSamplerObjectTest.SamplingState(gl.NEAREST, gl.NEAREST, gl.REPEAT, gl.MIRRORED_REPEAT, gl.REPEAT, -1000.0, 1000.0),39 new glsSamplerObjectTest.SamplingState(gl.NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, 1000.0)40 ),41 new glsSamplerObjectTest.TestSpec('diff_wrap_r', 'Different gl.TEXTURE_WRAP_R', gl.TEXTURE_2D,42 new glsSamplerObjectTest.SamplingState(gl.NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.MIRRORED_REPEAT, -1000.0, 1000.0),43 new glsSamplerObjectTest.SamplingState(gl.NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, 1000.0)44 ),45 new glsSamplerObjectTest.TestSpec('diff_min_filter', 'Different gl.TEXTURE_MIN_FILTER', gl.TEXTURE_2D,46 new glsSamplerObjectTest.SamplingState(gl.LINEAR, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, 1000.0),47 new glsSamplerObjectTest.SamplingState(gl.NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, 1000.0)48 ),49 new glsSamplerObjectTest.TestSpec('diff_mag_filter', 'Different gl.TEXTURE_MAG_FILTER', gl.TEXTURE_2D,50 new glsSamplerObjectTest.SamplingState(gl.NEAREST, gl.LINEAR, gl.REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, 1000.0),51 new glsSamplerObjectTest.SamplingState(gl.NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, 1000.0)52 ),53 new glsSamplerObjectTest.TestSpec('diff_max_lod', 'Different gl.TEXTURE_MAX_LOD', gl.TEXTURE_2D,54 new glsSamplerObjectTest.SamplingState(gl.NEAREST_MIPMAP_NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, 1000.0),55 new glsSamplerObjectTest.SamplingState(gl.NEAREST_MIPMAP_NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, -999.0)56 ),57 new glsSamplerObjectTest.TestSpec('diff_min_lod', 'Different gl.TEXTURE_MIN_LOD', gl.TEXTURE_2D,58 new glsSamplerObjectTest.SamplingState(gl.NEAREST_MIPMAP_NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, 0.0, 1000.0),59 new glsSamplerObjectTest.SamplingState(gl.NEAREST_MIPMAP_NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, 100.0, 1000.0)60 )61 ];62 /** @type {tcuTestCase.DeqpTest} */ var simpleTexture2D = tcuTestCase.newTest('single_tex_2d', 'Simple 2D texture with sampler');63 for (var testNdx = 0; testNdx < simpleTestCases.length; testNdx++)64 simpleTexture2D.addChild(new glsSamplerObjectTest.TextureSamplerTest(simpleTestCases[testNdx]));65 testGroup.addChild(simpleTexture2D);66 /** @type {Array<glsSamplerObjectTest.TestSpec>} */ var multiTestCases = [67 new glsSamplerObjectTest.TestSpec('diff_wrap_t', 'Different gl.TEXTURE_WRAP_T', gl.TEXTURE_2D,68 new glsSamplerObjectTest.SamplingState(gl.NEAREST, gl.NEAREST, gl.MIRRORED_REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, 1000.0),69 new glsSamplerObjectTest.SamplingState(gl.NEAREST, gl.NEAREST, gl.MIRRORED_REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, 1000.0),70 new glsSamplerObjectTest.SamplingState(gl.NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, 1000.0)71 ),72 new glsSamplerObjectTest.TestSpec('diff_wrap_s', 'Different gl.TEXTURE_WRAP_S', gl.TEXTURE_2D,73 new glsSamplerObjectTest.SamplingState(gl.NEAREST, gl.NEAREST, gl.REPEAT, gl.MIRRORED_REPEAT, gl.REPEAT, -1000.0, 1000.0),74 new glsSamplerObjectTest.SamplingState(gl.NEAREST, gl.NEAREST, gl.REPEAT, gl.MIRRORED_REPEAT, gl.REPEAT, -1000.0, 1000.0),75 new glsSamplerObjectTest.SamplingState(gl.NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, 1000.0)76 ),77 new glsSamplerObjectTest.TestSpec('diff_wrap_r', 'Different gl.TEXTURE_WRAP_R', gl.TEXTURE_2D,78 new glsSamplerObjectTest.SamplingState(gl.NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.MIRRORED_REPEAT, -1000.0, 1000.0),79 new glsSamplerObjectTest.SamplingState(gl.NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.MIRRORED_REPEAT, -1000.0, 1000.0),80 new glsSamplerObjectTest.SamplingState(gl.NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, 1000.0)81 ),82 new glsSamplerObjectTest.TestSpec('diff_min_filter', 'Different gl.TEXTURE_MIN_FILTER', gl.TEXTURE_2D,83 new glsSamplerObjectTest.SamplingState(gl.LINEAR, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, 1000.0),84 new glsSamplerObjectTest.SamplingState(gl.LINEAR, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, 1000.0),85 new glsSamplerObjectTest.SamplingState(gl.NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, 1000.0)86 ),87 new glsSamplerObjectTest.TestSpec('diff_mag_filter', 'Different gl.TEXTURE_MAG_FILTER', gl.TEXTURE_2D,88 new glsSamplerObjectTest.SamplingState(gl.NEAREST, gl.LINEAR, gl.REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, 1000.0),89 new glsSamplerObjectTest.SamplingState(gl.NEAREST, gl.LINEAR, gl.REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, 1000.0),90 new glsSamplerObjectTest.SamplingState(gl.NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, 1000.0)91 ),92 new glsSamplerObjectTest.TestSpec('diff_max_lod', 'Different gl.TEXTURE_MAX_LOD', gl.TEXTURE_2D,93 new glsSamplerObjectTest.SamplingState(gl.NEAREST_MIPMAP_NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, 1000.0),94 new glsSamplerObjectTest.SamplingState(gl.NEAREST_MIPMAP_NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, 1000.0),95 new glsSamplerObjectTest.SamplingState(gl.NEAREST_MIPMAP_NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, -999.0)96 ),97 new glsSamplerObjectTest.TestSpec('diff_min_lod', 'Different gl.TEXTURE_MIN_LOD', gl.TEXTURE_2D,98 new glsSamplerObjectTest.SamplingState(gl.NEAREST_MIPMAP_NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, 0.0, 1000.0),99 new glsSamplerObjectTest.SamplingState(gl.NEAREST_MIPMAP_NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, 0.0, 1000.0),100 new glsSamplerObjectTest.SamplingState(gl.NEAREST_MIPMAP_NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, 100.0, 1000.0)101 )102 ];103 /** @type {tcuTestCase.DeqpTest} */ var multiTexture2D = tcuTestCase.newTest('multi_tex_2d', 'Multiple texture units 2D texture with sampler');104 for (var testNdx = 0; testNdx < multiTestCases.length; testNdx++)105 multiTexture2D.addChild(new glsSamplerObjectTest.MultiTextureSamplerTest(multiTestCases[testNdx]));106 testGroup.addChild(multiTexture2D);107 /** @type {Array<glsSamplerObjectTest.TestSpec>} */ var simpleTestCases3D = [108 new glsSamplerObjectTest.TestSpec('diff_wrap_t', 'Different gl.TEXTURE_WRAP_T', gl.TEXTURE_3D,109 new glsSamplerObjectTest.SamplingState(gl.NEAREST, gl.NEAREST, gl.MIRRORED_REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, 1000.0),110 new glsSamplerObjectTest.SamplingState(gl.NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, 1000.0)111 ),112 new glsSamplerObjectTest.TestSpec('diff_wrap_s', 'Different gl.TEXTURE_WRAP_S', gl.TEXTURE_3D,113 new glsSamplerObjectTest.SamplingState(gl.NEAREST, gl.NEAREST, gl.REPEAT, gl.MIRRORED_REPEAT, gl.REPEAT, -1000.0, 1000.0),114 new glsSamplerObjectTest.SamplingState(gl.NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, 1000.0)115 ),116 new glsSamplerObjectTest.TestSpec('diff_wrap_r', 'Different gl.TEXTURE_WRAP_R', gl.TEXTURE_3D,117 new glsSamplerObjectTest.SamplingState(gl.NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.MIRRORED_REPEAT, -1000.0, 1000.0),118 new glsSamplerObjectTest.SamplingState(gl.NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, 1000.0)119 ),120 new glsSamplerObjectTest.TestSpec('diff_min_filter', 'Different gl.TEXTURE_MIN_FILTER', gl.TEXTURE_3D,121 new glsSamplerObjectTest.SamplingState(gl.LINEAR, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, 1000.0),122 new glsSamplerObjectTest.SamplingState(gl.NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, 1000.0)123 ),124 new glsSamplerObjectTest.TestSpec('diff_mag_filter', 'Different gl.TEXTURE_MAG_FILTER', gl.TEXTURE_3D,125 new glsSamplerObjectTest.SamplingState(gl.NEAREST, gl.LINEAR, gl.REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, 1000.0),126 new glsSamplerObjectTest.SamplingState(gl.NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, 1000.0)127 ),128 new glsSamplerObjectTest.TestSpec('diff_max_lod', 'Different gl.TEXTURE_MAX_LOD', gl.TEXTURE_3D,129 new glsSamplerObjectTest.SamplingState(gl.NEAREST_MIPMAP_NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, 1000.0),130 new glsSamplerObjectTest.SamplingState(gl.NEAREST_MIPMAP_NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, -999.0)131 ),132 new glsSamplerObjectTest.TestSpec('diff_min_lod', 'Different gl.TEXTURE_MIN_LOD', gl.TEXTURE_3D,133 new glsSamplerObjectTest.SamplingState(gl.NEAREST_MIPMAP_NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, 0.0, 1000.0),134 new glsSamplerObjectTest.SamplingState(gl.NEAREST_MIPMAP_NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, 100.0, 1000.0)135 )136 ];137 /** @type {tcuTestCase.DeqpTest} */ var simpleTexture3D = tcuTestCase.newTest('single_tex_3d', 'Simple 3D texture with sampler');138 for (var testNdx = 0; testNdx < simpleTestCases3D.length; testNdx++)139 simpleTexture3D.addChild(new glsSamplerObjectTest.TextureSamplerTest(simpleTestCases3D[testNdx]));140 testGroup.addChild(simpleTexture3D);141 /** @type {Array<glsSamplerObjectTest.TestSpec>} */ var multiTestCases3D = [142 new glsSamplerObjectTest.TestSpec('diff_wrap_t', 'Different gl.TEXTURE_WRAP_T', gl.TEXTURE_3D,143 new glsSamplerObjectTest.SamplingState(gl.NEAREST, gl.NEAREST, gl.MIRRORED_REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, 1000.0),144 new glsSamplerObjectTest.SamplingState(gl.NEAREST, gl.NEAREST, gl.MIRRORED_REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, 1000.0),145 new glsSamplerObjectTest.SamplingState(gl.NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, 1000.0)146 ),147 new glsSamplerObjectTest.TestSpec('diff_wrap_s', 'Different gl.TEXTURE_WRAP_S', gl.TEXTURE_3D,148 new glsSamplerObjectTest.SamplingState(gl.NEAREST, gl.NEAREST, gl.REPEAT, gl.MIRRORED_REPEAT, gl.REPEAT, -1000.0, 1000.0),149 new glsSamplerObjectTest.SamplingState(gl.NEAREST, gl.NEAREST, gl.REPEAT, gl.MIRRORED_REPEAT, gl.REPEAT, -1000.0, 1000.0),150 new glsSamplerObjectTest.SamplingState(gl.NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, 1000.0)151 ),152 new glsSamplerObjectTest.TestSpec('diff_wrap_r', 'Different gl.TEXTURE_WRAP_R', gl.TEXTURE_3D,153 new glsSamplerObjectTest.SamplingState(gl.NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.MIRRORED_REPEAT, -1000.0, 1000.0),154 new glsSamplerObjectTest.SamplingState(gl.NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.MIRRORED_REPEAT, -1000.0, 1000.0),155 new glsSamplerObjectTest.SamplingState(gl.NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, 1000.0)156 ),157 new glsSamplerObjectTest.TestSpec('diff_min_filter', 'Different gl.TEXTURE_MIN_FILTER', gl.TEXTURE_3D,158 new glsSamplerObjectTest.SamplingState(gl.LINEAR, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, 1000.0),159 new glsSamplerObjectTest.SamplingState(gl.LINEAR, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, 1000.0),160 new glsSamplerObjectTest.SamplingState(gl.NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, 1000.0)161 ),162 new glsSamplerObjectTest.TestSpec('diff_mag_filter', 'Different gl.TEXTURE_MAG_FILTER', gl.TEXTURE_3D,163 new glsSamplerObjectTest.SamplingState(gl.NEAREST, gl.LINEAR, gl.REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, 1000.0),164 new glsSamplerObjectTest.SamplingState(gl.NEAREST, gl.LINEAR, gl.REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, 1000.0),165 new glsSamplerObjectTest.SamplingState(gl.NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, 1000.0)166 ),167 new glsSamplerObjectTest.TestSpec('diff_max_lod', 'Different gl.TEXTURE_MAX_LOD', gl.TEXTURE_3D,168 new glsSamplerObjectTest.SamplingState(gl.NEAREST_MIPMAP_NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, 1000.0),169 new glsSamplerObjectTest.SamplingState(gl.NEAREST_MIPMAP_NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, 1000.0),170 new glsSamplerObjectTest.SamplingState(gl.NEAREST_MIPMAP_NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, -999.0)171 ),172 new glsSamplerObjectTest.TestSpec('diff_min_lod', 'Different gl.TEXTURE_MIN_LOD', gl.TEXTURE_3D,173 new glsSamplerObjectTest.SamplingState(gl.NEAREST_MIPMAP_NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, 0.0, 1000.0),174 new glsSamplerObjectTest.SamplingState(gl.NEAREST_MIPMAP_NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, 0.0, 1000.0),175 new glsSamplerObjectTest.SamplingState(gl.NEAREST_MIPMAP_NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, 100.0, 1000.0)176 )177 ];178 /** @type {tcuTestCase.DeqpTest} */ var multiTexture3D = tcuTestCase.newTest('multi_tex_3d', 'Multiple texture units 3D texture with sampler');179 for (var testNdx = 0; testNdx < multiTestCases3D.length; testNdx++)180 multiTexture3D.addChild(new glsSamplerObjectTest.MultiTextureSamplerTest(multiTestCases3D[testNdx]));181 testGroup.addChild(multiTexture3D);182 /** @type {Array<glsSamplerObjectTest.TestSpec>} */ var simpleTestCasesCube = [183 new glsSamplerObjectTest.TestSpec('diff_wrap_t', 'Different gl.TEXTURE_WRAP_T', gl.TEXTURE_CUBE_MAP,184 new glsSamplerObjectTest.SamplingState(gl.NEAREST, gl.NEAREST, gl.MIRRORED_REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, 1000.0),185 new glsSamplerObjectTest.SamplingState(gl.NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, 1000.0)186 ),187 new glsSamplerObjectTest.TestSpec('diff_wrap_s', 'Different gl.TEXTURE_WRAP_S', gl.TEXTURE_CUBE_MAP,188 new glsSamplerObjectTest.SamplingState(gl.NEAREST, gl.NEAREST, gl.REPEAT, gl.MIRRORED_REPEAT, gl.REPEAT, -1000.0, 1000.0),189 new glsSamplerObjectTest.SamplingState(gl.NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, 1000.0)190 ),191 new glsSamplerObjectTest.TestSpec('diff_wrap_r', 'Different gl.TEXTURE_WRAP_R', gl.TEXTURE_CUBE_MAP,192 new glsSamplerObjectTest.SamplingState(gl.NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.MIRRORED_REPEAT, -1000.0, 1000.0),193 new glsSamplerObjectTest.SamplingState(gl.NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, 1000.0)194 ),195 new glsSamplerObjectTest.TestSpec('diff_min_filter', 'Different gl.TEXTURE_MIN_FILTER', gl.TEXTURE_CUBE_MAP,196 new glsSamplerObjectTest.SamplingState(gl.LINEAR, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, 1000.0),197 new glsSamplerObjectTest.SamplingState(gl.NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, 1000.0)198 ),199 new glsSamplerObjectTest.TestSpec('diff_mag_filter', 'Different gl.TEXTURE_MAG_FILTER', gl.TEXTURE_CUBE_MAP,200 new glsSamplerObjectTest.SamplingState(gl.NEAREST, gl.LINEAR, gl.REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, 1000.0),201 new glsSamplerObjectTest.SamplingState(gl.NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, 1000.0)202 ),203 new glsSamplerObjectTest.TestSpec('diff_max_lod', 'Different gl.TEXTURE_MAX_LOD', gl.TEXTURE_CUBE_MAP,204 new glsSamplerObjectTest.SamplingState(gl.NEAREST_MIPMAP_NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, 1000.0),205 new glsSamplerObjectTest.SamplingState(gl.NEAREST_MIPMAP_NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, -999.0)206 ),207 new glsSamplerObjectTest.TestSpec('diff_min_lod', 'Different gl.TEXTURE_MIN_LOD', gl.TEXTURE_CUBE_MAP,208 new glsSamplerObjectTest.SamplingState(gl.NEAREST_MIPMAP_NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, 0.0, 1000.0),209 new glsSamplerObjectTest.SamplingState(gl.NEAREST_MIPMAP_NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, 100.0, 1000.0)210 )211 ];212 /** @type {tcuTestCase.DeqpTest} */ var simpleTextureCube = tcuTestCase.newTest('single_cubemap', 'Simple cubemap texture with sampler');213 for (var testNdx = 0; testNdx < simpleTestCasesCube.length; testNdx++)214 simpleTextureCube.addChild(new glsSamplerObjectTest.TextureSamplerTest(simpleTestCasesCube[testNdx]));215 testGroup.addChild(simpleTextureCube);216 /** @type {Array<glsSamplerObjectTest.TestSpec>} */ var multiTestCasesCube = [217 new glsSamplerObjectTest.TestSpec('diff_wrap_t', 'Different gl.TEXTURE_WRAP_T', gl.TEXTURE_CUBE_MAP,218 new glsSamplerObjectTest.SamplingState(gl.NEAREST, gl.NEAREST, gl.MIRRORED_REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, 1000.0),219 new glsSamplerObjectTest.SamplingState(gl.NEAREST, gl.NEAREST, gl.MIRRORED_REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, 1000.0),220 new glsSamplerObjectTest.SamplingState(gl.NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, 1000.0)221 ),222 new glsSamplerObjectTest.TestSpec('diff_wrap_s', 'Different gl.TEXTURE_WRAP_S', gl.TEXTURE_CUBE_MAP,223 new glsSamplerObjectTest.SamplingState(gl.NEAREST, gl.NEAREST, gl.REPEAT, gl.MIRRORED_REPEAT, gl.REPEAT, -1000.0, 1000.0),224 new glsSamplerObjectTest.SamplingState(gl.NEAREST, gl.NEAREST, gl.REPEAT, gl.MIRRORED_REPEAT, gl.REPEAT, -1000.0, 1000.0),225 new glsSamplerObjectTest.SamplingState(gl.NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, 1000.0)226 ),227 new glsSamplerObjectTest.TestSpec('diff_wrap_r', 'Different gl.TEXTURE_WRAP_R', gl.TEXTURE_CUBE_MAP,228 new glsSamplerObjectTest.SamplingState(gl.NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.MIRRORED_REPEAT, -1000.0, 1000.0),229 new glsSamplerObjectTest.SamplingState(gl.NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.MIRRORED_REPEAT, -1000.0, 1000.0),230 new glsSamplerObjectTest.SamplingState(gl.NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, 1000.0)231 ),232 new glsSamplerObjectTest.TestSpec('diff_min_filter', 'Different gl.TEXTURE_MIN_FILTER', gl.TEXTURE_CUBE_MAP,233 new glsSamplerObjectTest.SamplingState(gl.LINEAR, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, 1000.0),234 new glsSamplerObjectTest.SamplingState(gl.LINEAR, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, 1000.0),235 new glsSamplerObjectTest.SamplingState(gl.NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, 1000.0)236 ),237 new glsSamplerObjectTest.TestSpec('diff_mag_filter', 'Different gl.TEXTURE_MAG_FILTER', gl.TEXTURE_CUBE_MAP,238 new glsSamplerObjectTest.SamplingState(gl.NEAREST, gl.LINEAR, gl.REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, 1000.0),239 new glsSamplerObjectTest.SamplingState(gl.NEAREST, gl.LINEAR, gl.REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, 1000.0),240 new glsSamplerObjectTest.SamplingState(gl.NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, 1000.0)241 ),242 new glsSamplerObjectTest.TestSpec('diff_max_lod', 'Different gl.TEXTURE_MAX_LOD', gl.TEXTURE_CUBE_MAP,243 new glsSamplerObjectTest.SamplingState(gl.NEAREST_MIPMAP_NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, 1000.0),244 new glsSamplerObjectTest.SamplingState(gl.NEAREST_MIPMAP_NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, 1000.0),245 new glsSamplerObjectTest.SamplingState(gl.NEAREST_MIPMAP_NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, -1000.0, -999.0)246 ),247 new glsSamplerObjectTest.TestSpec('diff_min_lod', 'Different gl.TEXTURE_MIN_LOD', gl.TEXTURE_CUBE_MAP,248 new glsSamplerObjectTest.SamplingState(gl.NEAREST_MIPMAP_NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, 0.0, 1000.0),249 new glsSamplerObjectTest.SamplingState(gl.NEAREST_MIPMAP_NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, 0.0, 1000.0),250 new glsSamplerObjectTest.SamplingState(gl.NEAREST_MIPMAP_NEAREST, gl.NEAREST, gl.REPEAT, gl.REPEAT, gl.REPEAT, 100.0, 1000.0)251 )252 ];253 /** @type {tcuTestCase.DeqpTest} */ var multiTextureCube = tcuTestCase.newTest('multi_cubemap', 'Multiple texture units cubemap textures with sampler');254 for (var testNdx = 0; testNdx < multiTestCasesCube.length; testNdx++)255 multiTextureCube.addChild(new glsSamplerObjectTest.MultiTextureSamplerTest(multiTestCasesCube[testNdx]));256 testGroup.addChild(multiTextureCube);257 };258 es3fSamplerObjectTests.run = function(context) {259 gl = context;260 //Set up Test Root parameters261 var testName = 'sampler_object';262 var testDescription = 'Sampler Object Tests';263 var state = tcuTestCase.runner;264 state.testName = testName;265 state.setRoot(tcuTestCase.newTest(testName, testDescription, null));266 //Set up name and description of this test series.267 setCurrentTestName(testName);268 description(testDescription);269 try {270 //Create test cases271 es3fSamplerObjectTests.init();272 //Run test cases273 tcuTestCase.runTestCases();274 }275 catch (err) {276 testFailedOptions('Failed to es3fSamplerObjectTests.run tests', false);277 tcuTestCase.runner.terminate();278 }279 };...

Full Screen

Full Screen

testspecs.js

Source:testspecs.js Github

copy

Full Screen

1"use strict";2//contrib3const express = require("express");4const router = express.Router();5const winston = require("winston");6const jwt = require("express-jwt");7const async = require("async");8//mine9const config = require("../../config");10const logger = new winston.Logger(config.logger.winston);11const db = require("../../models");12function canedit(user, testspec) {13 if (user) {14 if (user.scopes.pwa && ~user.scopes.pwa.indexOf("admin")) return true;15 if (~testspec.admins.indexOf(user.sub.toString())) return true;16 }17 return false;18}19/**20 * @api {get} /testspecs Query Testspecs21 * @apiGroup Testspecs22 * @apiDescription Query testspecs registered by users23 24 * @apiParam {Object} [find] Mongo find query JSON.stringify & encodeURIComponent-ed - defaults to {}25 * To pass regex, you need to use {$regex: "...."} format instead of js: /.../ 26 * @apiParam {Object} [sort] Mongo sort object - defaults to _id. Enter in string format like "-name%20desc"27 * @apiParam {String} [select] Fields to return (admins will always be added). Multiple fields can be entered with %20 as delimiter28 * @apiParam {Number} [limit] Maximum number of records to return - defaults to 10029 * @apiParam {Number} [skip] Record offset for pagination (default to 0)30 * @apiHeader {String} Authorization A valid JWT token "Bearer: xxxxx"31 *32 * @apiSuccess {Object} hosts: List of testspecs objects(testspecs:), count: total number of testspecs (for paging)33 */34router.get(35 "/",36 jwt({ secret: config.admin.jwt.pub }),37 function (req, res, next) {38 var find = {};39 if (req.query.find) find = JSON.parse(req.query.find);40 //we need to select admins , or can't get _canedit set41 var select = req.query.select;42 if (select && !~select.indexOf("admins")) select += " admins";43 db.Testspec.find(find)44 .select(select)45 .limit(parseInt(req.query.limit) || 100)46 .skip(parseInt(req.query.skip) || 0)47 .sort(req.query.sort || "_id")48 .lean() //so that I can add _canedit later49 .exec(function (err, testspecs) {50 if (err) return next(err);51 db.Testspec.countDocuments(find).exec(function (err, count) {52 if (err) return next(err);53 //set _canedit flag for each specs54 testspecs.forEach(function (testspec) {55 testspec._canedit = canedit(req.user, testspec);56 });57 res.json({ testspecs: testspecs, count: count });58 });59 });60 }61);62/**63 * @api {post} /testspecs New testspec64 * @apiGroup Testspecs65 * @apiDescription Register new testspec66 *67 * @apiParam {String} service_type Service Type (bwctl, owamp, traceroute, ping, etc..)68 * @apiParam {String} name Name69 * @apiParam {String} [desc] Description70 * @apiParam {Object} specs Spec details (key/value pairs)71 * @apiParam {String[]} [admins] Array of admin IDs72 *73 * @apiHeader {String} authorization74 * A valid JWT token "Bearer: xxxxx"75 * @apiSuccess {Object} Testspec registered76 */77router.post(78 "/",79 jwt({ secret: config.admin.jwt.pub }),80 function (req, res, next) {81 if (!req.user.scopes.pwa || !~req.user.scopes.pwa.indexOf("user"))82 return res.status(401).end();83 db.Testspec.create(req.body, function (err, testspec) {84 if (err) return next(err);85 testspec = JSON.parse(JSON.stringify(testspec));86 testspec._canedit = canedit(req.user, testspec);87 res.json(testspec);88 });89 }90);91/**92 * @api {put} /testspecs/:id Update testspec93 * @apiGroup Testspecs94 * @apiDescription Update testspec information (service_type can be changed if it's not used by any test)95 *96 * @apiParam {String} [service_type] Service Type (bwctl, owamp, traceroute, ping, etc..)97 * @apiParam {String} [name] Name98 * @apiParam {String} [desc] Description99 * @apiParam {Object} [specs] Spec details (key/value pairs)100 * @apiParam {String[]} [admins] Array of admin IDs101 *102 * @apiHeader {String} authorization A valid JWT token "Bearer: xxxxx"103 *104 * @apiSuccess {Object} Testspec updated105 */106router.put(107 "/:id",108 jwt({ secret: config.admin.jwt.pub }),109 function (req, res, next) {110 db.Testspec.findById(req.params.id, function (err, testspec) {111 if (err) return next(err);112 if (!testspec)113 return next(114 new Error("can't find a testspec with id:" + req.params.id)115 );116 if (!canedit(req.user, testspec)) return res.status(401).end();117 if (req.body.service_type == testspec.service_type) update();118 else {119 //check to make sure if it's not used by a test120 db.Config.find(121 { "tests.testspec": testspec._id },122 function (err, tests) {123 if (err) return next(err);124 if (tests.length == 0) update();125 else {126 var names = "";127 tests.forEach(function (test) {128 names += test.name + ", ";129 });130 next(131 "You can not change service_type for this testspec. It is currently used by " +132 names133 );134 }135 }136 );137 }138 function update() {139 //console.log("req.body.service_type", req.body.service_type);140 //not used by anyone .. update (field no set won't be updated - unless it's set to undefined explicitly)141 testspec.service_type = req.body.service_type;142 testspec.name = req.body.name;143 testspec.desc = req.body.desc;144 testspec.specs = req.body.specs;145 testspec.schedule_type = req.body.schedule_type;146 testspec.admins = req.body.admins;147 testspec.update_date = new Date();148 if (testspec.service_type != "owamp") {149 testspec.schedule_type = "interval";150 }151 // Rename protocol to probe_type for trace tests152 if (testspec.service_type == "traceroute") {153 if (!req.body.specs.probe_type && req.body.specs.protocol) {154 testspec.specs.probe_type = req.body.specs.protocol;155 delete testspec.specs.protocol;156 } else {157 if (req.body.specs.probe_type) {158 testspec.specs.probe_type =159 req.body.specs.probe_type;160 delete testspec.specs.protocol;161 }162 }163 }164 testspec.save(function (err) {165 if (err) return next(err);166 testspec = JSON.parse(JSON.stringify(testspec));167 testspec._canedit = canedit(req.user, testspec);168 res.json(testspec);169 });170 }171 });172 }173);174/**175 * @api {delete} /testspecs/:id Remove testspec176 * @apiGroup Testspecs177 * @apiDescription Remove testspec registration - if it's not used by any test178 * @apiHeader {String} authorization179 * A valid JWT token "Bearer: xxxxx"180 * @apiSuccessExample {json} Success-Response:181 * HTTP/1.1 200 OK182 * {183 * "status": "ok"184 * }185 */186router.delete(187 "/:id",188 jwt({ secret: config.admin.jwt.pub }),189 function (req, res, next) {190 db.Testspec.findById(req.params.id, function (err, testspec) {191 if (err) return next(err);192 if (!testspec)193 return next(194 new Error("can't find a testspec with id:" + req.params.id)195 );196 async.series(197 [198 //check access199 function (cb) {200 if (canedit(req.user, testspec)) {201 cb();202 } else {203 cb("You don't have access to remove this testspec");204 }205 },206 //check foreign key dependencies on test207 function (cb) {208 db.Config.find(209 { "tests.testspec": testspec._id },210 function (err, tests) {211 if (err) return cb(err);212 var names = "";213 tests.forEach(function (test) {214 names += test.name + ", ";215 });216 if (names == "") {217 cb();218 } else {219 cb(220 "You can not remove this testspec. It is currently used by " +221 names222 );223 }224 }225 );226 },227 ],228 function (err) {229 if (err) return next(err);230 //all good.. remove231 testspec.remove().then(function () {232 res.json({ status: "ok" });233 });234 }235 );236 });237 }238);...

Full Screen

Full Screen

showHide.js

Source:showHide.js Github

copy

Full Screen

1// -----------------------------------------------------------------------------------------------------------------2// Documentation of showHide.js3// -----------------------------------------------------------------------------------------------------------------4/*5This javascript is used to show or hide substeps of the Canoo Webtest 'group' steptype in a HTML Webtest Resultfile.6The script provides functions to show or hide substeps for different levels in the hierarchically structured html tree:7 1) For a single group step: showSubstepsOfGroup / hideSubstepsOfGroup / changeLevelOfDetailForGroup8 2) For a testspec: showAllSubstepsOfTestspec / hideAllSubstepsOfTestspec9 3) For the entire document: hideAllSubstepsOnPage10The function's algorithm is as follows:11 1) Functions for a single group step:12 The functions for a single group step get as argument the node which represents13 the image that has been clicked in the browser to show or hide the substeps of a group step.14 These functions navigate in the DOM tree to the node which is the parent of all substeps of the group.15 For each substep the attribute 'style.display' is assigned the appropriate value to show or hide the substep.16 2/3) Functions for a testspec or the entire document:17 These functions get as argument the node which represents the image that has been clicked18 in the browser to show or hide the substeps of the group steps within a tespec or within the entire19 document. They determine each image in the scope of the testpec respectively in the document20 that is used to show or hide the substeps of a single group step and use each of these images21 to call the according function for a single group step to show or hide the substeps for each22 of the group steps.23The functions are based on the following structure of the HTML document:24 1) showSubstepsOfGroup/hideSubstepsOfGroup:25 <tr> <!-- tablerow for one step in a testspec -->26 <td> <!-- (( 2 )) SKRIPT: td node = imageForGroup.parentNode -->27 <!-- position of step in testspec -->28 <b>1</b>29 <br>30 <img onclick="changeLevelOfDetailForGroup(this)" name="collapseButton" src="./images/expandall.png">31 <!-- (( 1 )) SKRIPT: img node = imageForGroup -->32 </td>33 <td> <!-- result of step execution (failed, successful, not executed) -->34 <img src="./images/ok.gif">35 </td>36 <td> <!-- stepType and stepID -->37 <b>group</b>38 <br>39 stepID here and optional lastResult40 </td>41 <td> <!-- (( 3 )) SKRIPT: td node = tdContainingImage.nextSibling.nextSibling.nextSibling -->42 <table>43 <tr><th>No</th><th>Result</th><th>Name</th><th>Parameter</th><th>Duration</th></tr>44 <tr> ... substeps of group step ... </tr>45 2) showAllSubstepsOfTestspec/hideAllSubstepsOfTestspec:46 <p> <!-- (( 2 )) SKRIPT: p node: pContainingImage = imageForTestSpec.parentNode47 <img alt="show all substeps of 'group' steps in testspec" src="./images/expandall.png" onclick="showAllSubstepsOfTestspec(this)">48 <img alt="hide all substeps of 'group' steps in testspec" src="./images/collapseall.png" onclick="hideAllSubstepsOfTestspec(this)">49 <!-- (( 1 )) SKRIPT: img node = imageForTestSpec -->50 </p>51 <table> <!-- (( 3 )) SKRIPT: table node = pContainingImage.nextSibling -->52 <tr><th>No</th><th>Result</th><th>Name</th><th>Parameter</th><th>Duration</th></tr>53 <tr> ... steps of testspec ... <tr>54*/55var fExpandSource, fCollapseSource;56/**57 * Function must be called early, such as 'onLoad', to set the two global variables with the two parameters.58 * @param expandSourceVar name of the icon file to show when the group is closed.59 * @param collapseSourceVar name of the icon file to show when the group is open.60 */61function initExpandCollapse(expandSourceVar, collapseSourceVar) {62 fExpandSource = expandSourceVar;63 fCollapseSource = collapseSourceVar;64}65/**66 * Hide all sub-steps of a test spec.67 * The desired test spec is identified by the 'collapse' image displayed above the table.68 */69function hideAllSubstepsOfTestspec(imageForTestSpec) {70 hideAllSubsteps(locateTestSpecTable(imageForTestSpec));71}72function hideAllSubsteps(nodeContainingStepsOfTestspec) {73 var images = nodeContainingStepsOfTestspec.getElementsByTagName("img");74 for (var i = 0; i < images.length; i++) {75 if (images[i].getAttribute("name") == "collapseButton") {76 hideSubstepsOfGroup(images[i]);77 }78 }79}80/**81 * Show all sub-steps of a test spec.82 * The desired test spec is identified by the 'expand' image displayed above the table.83 */84function showAllSubstepsOfTestspec(imageForTestSpec) {85 showAllSubsteps(locateTestSpecTable(imageForTestSpec));86}87function showAllSubsteps(nodeContainingStepsOfTestspec) {88 var images = nodeContainingStepsOfTestspec.getElementsByTagName("img");89 for (var i = 0; i < images.length; i++) {90 if (images[i].getAttribute("name") == "collapseButton") {91 showSubstepsOfGroup(images[i]);92 }93 }94}95function changeLevelOfDetailForGroup(imageForGroup) {96 if (imageForGroup.src.indexOf(fCollapseSource) > -1) {97 hideSubstepsOfGroup(imageForGroup);98 } 99 else {100 showSubstepsOfGroup(imageForGroup);101 }102}103function hideSubstepsOfGroup(imageForGroup) {104 changeSubstepsOfGroup(imageForGroup, "collapsed", fExpandSource);105}106function showSubstepsOfGroup(imageForGroup) {107 changeSubstepsOfGroup(imageForGroup, "expanded", fCollapseSource);108}109function changeSubstepsOfGroup(imageForGroup, displayStyle, imageName) {110 // how to locate table[@class="expanded"] or table[@class="collapsed]?111 // moves two nodes up from the image to the row, then gets the 4th td112 // this handle any possible child that aren't element113 var tdContainingSubsteps = imageForGroup.parentNode.parentNode.getElementsByTagName('TD')[3];114 var substeps = tdContainingSubsteps.childNodes;115 for (var j = 1; j < substeps.length; j++) {116 // Note: nodeType==1 denotes Element; see e.g. <http://www.zytrax.com/tech/dom/nodetype.html>117 if (substeps[j].nodeType == 1) {118 substeps[j].className = displayStyle;119 }120 }121 imageForGroup.src = imageForGroup.src.substr(0, imageForGroup.src.lastIndexOf("/") + 1) + imageName;122}123/**124 * Locate the table that belongs to a global 'collapse' or 'expand' button.125 */126function locateTestSpecTable(imageForTestSpec) {127 var pContainingStepsOfTestspec = imageForTestSpec.parentNode;128 do {129 pContainingStepsOfTestspec = pContainingStepsOfTestspec.nextSibling;130 // Note: nodeType==1 denotes Elements; see e.g. <http://www.zytrax.com/tech/dom/nodetype.html>131 }132 while (pContainingStepsOfTestspec.nodeType != 1);133 return pContainingStepsOfTestspec;134}135/**136 * Make sure that the target of the link is visible.137 * @param link An anchor to an error.138 */139function showTargetStep(link) {140 if (link.href.indexOf("#") > -1) {141 showStep(getNamedAnchor(link.href.substr(link.href.indexOf("#") + 1)));142 }143 // lets the browser follows the link144 return false;145}146/**147 * Locate the error on the page.148 * @param name The name of the anchor149 * @return node The anchor for the error. Is null if the anchor isn't on the page.150 */151function getNamedAnchor(name) {152 var elements = document.getElementsByName(name);153 for (var i = 0; i < elements.length; i++) {154 if (elements[i].nodeName == "A") {155 return elements[i];156 }157 }158 return null;159}160/**161 * Expand all levels from a failing node to the root of the webtest table.162 * @param node The anchor for the error.163 */164function showStep(node) {165 if (node == null) {166 return;167 }168 do {169 node = node.parentNode;170 } while (node.nodeName != "TABLE");171 if (node.className == "collapsed") {172 showStep(node);173 // moves two nodes up from the table to the row, then gets the 1st (and only) image in the 1st td174 // this handle any possible child that aren't element175 showSubstepsOfGroup(node.parentNode.parentNode.getElementsByTagName('TD')[0].getElementsByTagName('IMG')[0]);176 }177}178/**179 Toggle the display of the first nextSibling of _node with nodeName _type (if any)180 */181function toggleDisplayNext(_node, _type) {182 var oNode = findNext(_node, _type);183 if (oNode) {184 var bDisplayed = (oNode.style.display != "none");185 oNode.style.display = bDisplayed ? "none" : "inline";186 var oImg = findToggleImage(_node);187 if (oImg) {188 var newFileName = bDisplayed ? "expandPlus.png" : "expandMinus.png";189 oImg.src = oImg.src.replace(/[^/]*$/, newFileName);190 oImg.alt = bDisplayed ? "Show " : "Hide ";191 }192 }193}194/**195 Finds the first nextSibling of _node with the provided node name196 */197function findNext(_node, _nodeName) {198 var nextNode = _node.nextSibling;199 while (nextNode != null && nextNode.nodeName != _nodeName) {200 nextNode = nextNode.nextSibling;201 }202 return nextNode;203}204/**205 Find the toggle image for the node. This is the node itself (if it is an image) else the first image206 child of the node.207 */208function findToggleImage(_oNode) {209 if (_oNode.tagName == "IMG") {210 return _oNode;211 }212 var imgs = _oNode.getElementsByTagName("img");213 return (imgs.length > 0) ? imgs[0] : null;...

Full Screen

Full Screen

subresource-test.js

Source:subresource-test.js Github

copy

Full Screen

1if (window.testRunner) {2 testRunner.dumpAsText();3 testRunner.waitUntilDone();4}5var currentTest;6var tests;7var uniqueId;8var now;9var loadedFrameCount = 0;10var frame1 = document.createElement('iframe');11frame1.setAttribute('style', 'visibility:hidden;width:0;height:0');12frame1.setAttribute('src', 'resources/test-frame.html');13document.body.appendChild(frame1);14frame1.onload = function () { loadedFrameCount++; }15var frame2 = document.createElement('iframe');16frame2.setAttribute('style', 'visibility:hidden;width:0;height:0');17frame2.setAttribute('src', 'resources/test-frame.html');18document.body.appendChild(frame2);19var consoleDiv = document.createElement('div');20document.body.appendChild(consoleDiv);21frame2.onload = function () { loadedFrameCount++; }22function getServerDate()23{24 var req = new XMLHttpRequest();25 var t0 = new Date().getTime();26 req.open('GET', "/cache/resources/current-time.cgi", false /* blocking */);27 req.send();28 var serverToClientTime = (new Date().getTime() - t0) / 2;29 if (req.status != 200) {30 console.log("unexpected status code " + req.status + ", expected 200.");31 return new Date();32 }33 return new Date((parseInt(req.responseText) * 1000) + serverToClientTime);34}35var serverClientTimeDelta = getServerDate().getTime() - new Date().getTime();36function loadTestFrame(frame, testSpec)37{38 var first = true;39 var queryString = 'cache-simulator.cgi?uniqueId=' + uniqueId + '&';40 for (var header in testSpec.testHeaders) {41 if (!first)42 queryString += '&';43 var value = testSpec.testHeaders[header];44 if (value == '[now+10s]')45 value = new Date(now.getTime() + 10 * 1000).toUTCString();46 else if (value == '[now-10s]')47 value = new Date(now.getTime() - 10 * 1000).toUTCString();48 else if (value == '[now+3600s]')49 value = new Date(now.getTime() + 3600 * 1000).toUTCString();50 else if (value == '[now-3600s]')51 value = new Date(now.getTime() - 3600 * 1000).toUTCString();52 else if (value == '[now]')53 value = new Date(now.getTime()).toUTCString();54 queryString += header + '=' + value;55 first = false;56 }57 var doc = frame.contentDocument;58 var head = doc.getElementsByTagName('head')[0];59 var scr = doc.createElement('script');60 head.appendChild(scr);61 scr.onload = function () { setTimeout(function () { frameLoaded(frame, testSpec); }, 0); }62 scr.setAttribute('src', queryString);63}64function frameLoaded(frame, testSpec)65{66 if (frame == frame1) {67 setTimeout(function () { loadTestFrame(frame2, testSpec) }, testSpec.delay * 1000);68 return;69 }70 testComplete(testSpec);71}72function nextTest()73{74 var testSpec = tests[currentTest];75 uniqueId = Math.floor(100000000 * Math.random());76 now = new Date(new Date().getTime() + serverClientTimeDelta);77 if (!testSpec) {78 if (window.testRunner)79 testRunner.notifyDone();80 return;81 }82 loadTestFrame(frame1, testSpec);83 currentTest++;84}85function testComplete(testSpec)86{87 var line = document.createElement('div');88 var result = frame1.contentWindow.randomNumber == frame2.contentWindow.randomNumber ? 'Cached' : 'Uncached';89 var passed = result == testSpec.expectedResult;90 if (testSpec.description)91 line.innerHTML += testSpec.description;92 else {93 for (var header in testSpec.testHeaders)94 line.innerHTML += header + ": " + testSpec.testHeaders[header] + "; ";95 }96 if (testSpec.delay)97 line.innerHTML += "[delay=" + testSpec.delay + "s] "98 line.innerHTML += " (result=" + result + " expected=" + testSpec.expectedResult + ") ";99 line.innerHTML += passed ? "<font color=green>PASS</font> " : "<font color=red>FAIL</font> "100 consoleDiv.appendChild(line);101 nextTest();102}103function runTests()104{105 currentTest = 0;106 if (loadedFrameCount==2)107 nextTest();108 else109 setTimeout(runTests, 100);...

Full Screen

Full Screen

ava.config.js

Source:ava.config.js Github

copy

Full Screen

1const process = require('process');2let testSpec = '(spec)';3if (!process.env.TESTSPEC) {4 testSpec = '(spec)';5} else if (process.env.TESTSPEC === 'spec') {6 testSpec = '(spec)';7} else if (process.env.TESTSPEC === 'test') {8 testSpec = '(test)';9} else {10 testSpec = '(spec|test)';11}12export default function config() {13 return {14 files: [15 'client/**/*.' + testSpec + '.js',16 'pages/**/*.' + testSpec + '.js',17 'server/**/*.' + testSpec + '.js',18 'test/**/*.' + testSpec + '.js'19 ],20 sources: ['client/**/*', 'pages/**/*', 'server/**/*', 'test/**/*'],21 cache: false,22 concurrency: 5,23 failFast: true,24 failWithoutAssertions: false,25 environmentVariables: {26 NODE_ENV: 'testing',27 },28 tap: true,29 verbose: true,30 compileEnhancements: false,31 require: [32 'esm',33 './.babel.register.test.js'34 ],35 babel: {36 testOptions: {37 plugins: [38 'babel-plugin-rewire'39 ],40 },41 },42 };...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

1'use strict';2require('./lib/exit-unless-test');3const mocha = require('./lib/mocha-e2e').mocha;4const path = require('path');5const only = 'only';6const skip = 'skip';7let tests = [8 'login',9 'subscription'10];11tests = tests.map(testSpec => (testSpec.constructor === Array ? testSpec : [testSpec]));12tests = tests.filter(testSpec => testSpec[1] !== skip);13if (tests.some(testSpec => testSpec[1] === only)) {14 tests = tests.filter(testSpec => testSpec[1] === only);15}16for (const testSpec of tests) {17 const testPath = path.join(__dirname, 'tests', testSpec[0] + '.js');18 mocha.addFile(testPath);19}20mocha.run(failures => {21 process.exit(failures); // exit with non-zero status if there were failures...

Full Screen

Full Screen

jest.config.js

Source:jest.config.js Github

copy

Full Screen

1const process = require('process');2let testSpec = '(spec)';3if (!process.env.TESTSPEC) {4 testSpec = '(spec)';5} else if (process.env.TESTSPEC === 'spec') {6 testSpec = '(spec)';7} else if (process.env.TESTSPEC === 'test') {8 testSpec = '(test)';9} else {10 testSpec = '(spec|test)';11}12module.exports = {13 moduleNameMapper: {14 '^.*\\.css$': '<rootDir>/test/stubs/stub.css',15 '^.*\\.jpg$': '<rootDir>/test/stubs/stub.jpg',16 '^.*\\.png$': '<rootDir>/test/stubs/stub.png',17 '^.*\\.scss$': '<rootDir>/test/stubs/stub.scss',18 },19 testMatch: ['**/?(*.)+' + testSpec + '.jsx'],...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('My First Test', function() {2 it('Does not do much!', function() {3 expect(true).to.equal(true)4 })5})6describe('My First Test', function() {7 it('Does not do much!', function() {8 expect(true).to.equal(true)9 })10})11describe('My First Test', function() {12 it('Does not do much!', function() {13 expect(true).to.equal(true)14 })15})16describe('My First Test', function() {17 it('Does not do much!', function() {18 expect(true).to.equal(true)19 })20})21describe('My First Test', function() {22 it('Does not do much!', function() {23 expect(true).to.equal(true)24 })25})26describe('My First Test', function() {27 it('Does not do much!', function() {28 expect(true).to.equal(true)29 })30})31describe('My First Test', function() {32 it('Does not do much!', function() {33 expect(true).to.equal(true)34 })35})36describe('My First Test', function() {37 it('Does not do much!', function() {38 expect(true).to.equal(true)39 })40})41describe('My First Test', function() {42 it('Does not do much!', function() {43 expect(true

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('My First Test', function() {2 it('Does not do much!', function() {3 expect(true).to.equal(true)4 })5 })6describe('My First Test', function() {7 it('Does not do much!', function() {8 expect(true).to.equal(true)9 })10 })11describe('My First Test', function() {12 it('Does not do much!', function() {13 expect(true).to.equal(true)14 })15 })16describe('My First Test', function() {17 it('Does not do much!', function() {18 expect(true).to.equal(true)19 })20 })21describe('My First Test', function() {22 it('Does not do much!', function() {23 expect(true).to.equal(true)24 })25 })26describe('My First Test', function() {27 it('Does not do much!', function() {28 expect(true).to.equal(true)29 })30 })31describe('My First Test', function() {32 it('Does not do much!', function() {33 expect(true).to.equal(true)34 })35 })36describe('My First Test', function() {37 it('Does not do much!', function() {38 expect(true).to.equal(true)39 })40 })41describe('My First Test', function() {42 it('Does not do much!', function() {43 expect(true).to.equal(true)44 })45 })46describe('My First Test', function() {47 it('Does not do much!', function() {48 expect(true).to.equal(true)49 })50 })51describe('My First Test', function() {52 it('Does not do much!', function() {53 expect(true).to.equal(true)54 })55 })56describe('My First Test', function() {57 it('Does not do much!', function() {58 expect(true).to.equal(true)59 })60 })

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('My First Test', function() {2 it('Does not do much!', function() {3 expect(true).to.equal(true)4 })5})6describe('My First Test', function() {7 it('Does not do much!', function() {8 expect(true).to.equal(true)9 })10})

Full Screen

Using AI Code Generation

copy

Full Screen

1describe("My First Test", function() {2 it("Does not do much!", function() {3 expect(true).to.equal(true)4 })5})6describe("My First Test", function() {7 it("Does not do much!", function() {8 expect(true).to.equal(true)9 })10})11describe("My First Test", function() {12 it("Does not do much!", function() {13 expect(true).to.equal(true)14 })15})16describe("My First Test", function() {17 it("Does not do much!", function() {18 expect(true).to.equal(true)19 })20})21describe("My First Test", function() {22 it("Does not do much!", function() {23 expect(true).to.equal(true)24 })25})26describe("My First Test", function() {27 it("Does not do much!", function() {28 expect(true).to.equal(true)29 })30})31describe("My First Test", function() {32 it("Does not do much!", function() {33 expect(true).to.equal(true)34 })35})36describe("My First Test", function() {37 it("Does not do much!", function() {38 expect(true).to.equal(true)39 })40})41describe("My First Test", function() {42 it("Does not do much!", function() {43 expect(true).to.equal(true)44 })45})46describe("My First Test", function() {47 it("Does not do much!", function() {48 expect(true).to.equal(true)49 })

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('Test', function () {2 it('test', function () {3 cy.get('#username').type('admin')4 cy.get('#password').type('admin')5 cy.get('#login').click()6 cy.get('#username').should('have.value', 'admin')7 cy.get('#password').should('have.value', 'admin')8 cy.get('#login').should('have.value', 'Login')9 cy.get('#login').click()10 cy.get('#logout').click()11 })12})13{14}15describe('Test', function () {16 it('test', function () {17 cy.get('#username').type('admin')18 cy.get('#password').type('admin')19 cy.get('#login').click()20 cy.get('#username').should('have.value', 'admin')21 cy.get('#password').should('have.value', 'admin')22 cy.get('#login').should('have.value', 'Login')23 cy.get('#login').click()24 cy.get('#logout').click()25 })26})

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('Test', () => {2 it('Test', () => {3 cy.testSpec('test.spec.js');4 });5});6describe('Test', () => {7 it('Test', () => {8 cy.testSpec('test.js');9 });10});11describe('Test', () => {12 it('Test', () => {13 cy.testSpec('test.spec.js');14 });15});16describe('Test', () => {17 it('Test', () => {18 cy.testSpec('test.spec.js');19 });20});21describe('Test', () => {22 it('Test', () => {23 cy.testSpec('test.spec.js');24 });25});26describe('Test', () => {27 it('Test', () => {28 cy.testSpec('test.spec.js');29 });30});31describe('Test', () => {32 it('Test', () => {33 cy.testSpec('test.spec.js');34 });35});36describe('Test', () => {37 it('Test', () => {38 cy.testSpec('test.spec.js');39 });40});41describe('Test', () => {42 it('Test', () => {43 cy.testSpec('test.spec.js');44 });45});46describe('Test', () => {47 it('Test', () => {48 cy.testSpec('test.spec.js');49 });50});51describe('Test', () => {52 it('Test', () => {53 cy.testSpec('test.spec.js');54 });55});56describe('Test',

Full Screen

Using AI Code Generation

copy

Full Screen

1describe("Test", () => {2 it("Test", () => {3 cy.testSpec("test.spec");4 });5});6{7 "scripts": {8 },9 "devDependencies": {10 }11}12CypressError: Timed out retrying: cy.task('getSpec', 'test.spec') failed with the following error:13CypressError: Timed out retrying: cy.task('getSpec', 'test.spec') failed with the following error:14CypressError: Timed out retrying: cy.task('getSpec', 'test.spec') failed with the following error:15CypressError: Timed out retrying: cy.task('getSpec', 'test.spec') failed with the following error:16CypressError: Timed out retrying: cy.task('getSpec', 'test.spec') failed with the following error:

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('My First Test', function() {2 it('Does not do much!', function() {3 expect(true).to.equal(true)4 })5})6{7}8describe('My First Test', function() {9 it('Does not do much!', function() {10 expect(true).to.equal(true)11 })12})13describe('My First Test', function() {14 it('Does not do much!', function() {15 expect(true).to.equal(true)16 })17})18describe('My First Test', function() {19 it('Does not do much!', function() {20 expect(true).to.equal(true)21 })22})23describe('My First Test', function() {24 it('Does not do much!', function() {25 expect(true).to.equal(true)26 })27})

Full Screen

Cypress Tutorial

Cypress is a renowned Javascript-based open-source, easy-to-use end-to-end testing framework primarily used for testing web applications. Cypress is a relatively new player in the automation testing space and has been gaining much traction lately, as evidenced by the number of Forks (2.7K) and Stars (42.1K) for the project. LambdaTest’s Cypress Tutorial covers step-by-step guides that will help you learn from the basics till you run automation tests on LambdaTest.

Chapters:

  1. What is Cypress? -
  2. Why Cypress? - Learn why Cypress might be a good choice for testing your web applications.
  3. Features of Cypress Testing - Learn about features that make Cypress a powerful and flexible tool for testing web applications.
  4. Cypress Drawbacks - Although Cypress has many strengths, it has a few limitations that you should be aware of.
  5. Cypress Architecture - Learn more about Cypress architecture and how it is designed to be run directly in the browser, i.e., it does not have any additional servers.
  6. Browsers Supported by Cypress - Cypress is built on top of the Electron browser, supporting all modern web browsers. Learn browsers that support Cypress.
  7. Selenium vs Cypress: A Detailed Comparison - Compare and explore some key differences in terms of their design and features.
  8. Cypress Learning: Best Practices - Take a deep dive into some of the best practices you should use to avoid anti-patterns in your automation tests.
  9. How To Run Cypress Tests on LambdaTest? - Set up a LambdaTest account, and now you are all set to learn how to run Cypress tests.

Certification

You can elevate your expertise with end-to-end testing using the Cypress automation framework and stay one step ahead in your career by earning a Cypress certification. Check out our Cypress 101 Certification.

YouTube

Watch this 3 hours of complete tutorial to learn the basics of Cypress and various Cypress commands with the Cypress testing at LambdaTest.

Run Cypress automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful