void runTest() { beginTest ("EncryptedString"); // test with some known keys const String knownPublicKey ("11,7eb9c1c3bc8360d1f263f8ee45d98b01"); const String knownPrivateKey ("2545b175ce0885e2fb72f1b59bbf8261,7eb9c1c3bc8360d1f263f8ee45d98b01"); expectEquals (EncryptedString::encrypt ("hello world!", knownPublicKey), String ("16.PcHEsm3XRKxv0V8hMeKv5A")); expectEquals (EncryptedString::decrypt ("16.PcHEsm3XRKxv0V8hMeKv5A", knownPrivateKey), String ("hello world!")); expectEquals (EncryptedString::encrypt ("hello world!", knownPublicKey, true), String ("508714ed8963d222c3b5d58bcdb7c07a")); expectEquals (EncryptedString::decrypt ("508714ed8963d222c3b5d58bcdb7c07a", knownPrivateKey, true), String ("hello world!")); // test with some generated keys RSAKey publicKey, privateKey; RSAKey::createKeyPair (publicKey, privateKey, 128); String encryptedString (EncryptedString::encrypt ("hello world!", publicKey.toString())); String decryptedString (EncryptedString::decrypt (encryptedString, privateKey.toString())); expectEquals (decryptedString, String ("hello world!")); }
void chunkedYieldingTest () { setup ("chunkedYieldingTest"); std::string lastYield; auto yield = [&]() { lastYield = output_; }; auto output = chunkedYieldingOutput ( Json::stringOutput (output_), yield, 5); output ("hello"); expectResult ("hello"); expectEquals (lastYield, ""); output (", th"); // Goes over the boundary. expectResult ("hello, th"); expectEquals (lastYield, ""); output ("ere!"); // Forces a yield. expectResult ("hello, there!"); expectEquals (lastYield, "hello, th"); output ("!!"); expectResult ("hello, there!!!"); expectEquals (lastYield, "hello, th"); output (""); // Forces a yield. expectResult ("hello, there!!!"); expectEquals (lastYield, "hello, there!!!"); }
static int memTest(void) { unsigned char buffer1[10] = {1,2,3,4,5,6,7,8,9,10,}, buffer2[10] = {0,}; unsigned char *src, *dst; unsigned int i; anmatMemcpy(buffer2, buffer1, 10); for (i = 0; i <= 9; i ++) { expectEquals(buffer2[i], buffer1[i]); } src = &buffer1[0]; dst = &buffer1[2]; anmatMemcpy(dst, src, 5); expectEquals(dst[0], 1); expectEquals(dst[1], 2); expectEquals(dst[2], 3); expectEquals(dst[3], 4); expectEquals(dst[4], 5); src = &buffer1[7]; dst = &buffer1[6]; anmatMemcpy(dst, src, 3); expectEquals(dst[0], 8); expectEquals(dst[1], 9); expectEquals(dst[2], 10); return 0; }
//============================================================================== void expectValuesConsistent (MPEValue value, int expectedValueAs7BitInt, int expectedValueAs14BitInt, float expectedValueAsSignedFloat, float expectedValueAsUnsignedFloat) { expectEquals (value.as7BitInt(), expectedValueAs7BitInt); expectEquals (value.as14BitInt(), expectedValueAs14BitInt); expectFloatWithinRelativeError (value.asSignedFloat(), expectedValueAsSignedFloat, 0.0001f); expectFloatWithinRelativeError (value.asUnsignedFloat(), expectedValueAsUnsignedFloat, 0.0001f); }
//============================================================================== void testTruncateToFit (int masterChannelFirst, int numNoteChannelsFirst, int masterChannelSecond, int numNoteChannelsSecond, bool expectedRetVal, int masterChannelFirstAfter, int numNoteChannelsFirstAfter) { MPEZone first (masterChannelFirst, numNoteChannelsFirst); MPEZone second (masterChannelSecond, numNoteChannelsSecond); expect (first.truncateToFit (second) == expectedRetVal); expectEquals (first.getMasterChannel(), masterChannelFirstAfter); expectEquals (first.getNumNoteChannels(), numNoteChannelsFirstAfter); }
void compareEventQueues (const std::deque<AnalyticsDestination::AnalyticsEvent>& a, const std::deque<AnalyticsDestination::AnalyticsEvent>& b) { const auto numEntries = a.size(); expectEquals ((int) b.size(), (int) numEntries); for (size_t i = 0; i < numEntries; ++i) { expectEquals (a[i].name, b[i].name); expect (a[i].timestamp == b[i].timestamp); } }
//============================================================================== void testMidiBuffer (MidiBuffer& buffer, const uint8* expectedBytes, int expectedBytesSize) { uint8 actualBytes[128] = { 0 }; extractRawBinaryData (buffer, actualBytes, sizeof (actualBytes)); expectEquals (std::memcmp (actualBytes, expectedBytes, (std::size_t) expectedBytesSize), 0); }
void MonitorTests::multiThreadedCallBackTest() { beginTest("Concurrent CallBack Test"); Monitor monitor; monitor.startMonitoring(); OwnedArray<SocketListener> listeners; for (int i = 0; i < 50 ; i++) { SocketListener* listener = new SocketListener(); listener->initializeSockets((40780 + (5*i)), &monitor, String("quassel") + String(i*20)); listeners.add(listener); } for (int i = 0; i < 50 ; i++) { pool->addJob(listeners[i], false); } while(pool->getNumJobs() > 0 ) { Thread::sleep(20); } monitor.stop(); for (int i = 0; i < 50 ; i++) { expectEquals(listeners[i]->was_informed , true); } }
void testThreads (int const threadCount) { String s; s << "threadCount = " << String (threadCount); beginTestCase (s); TestCallback cb (threadCount); Workers w (cb, "Test", 0); expect (w.getNumberOfThreads () == 0); w.setNumberOfThreads (threadCount); expect (w.getNumberOfThreads () == threadCount); for (int i = 0; i < threadCount; ++i) w.addTask (); // 10 seconds should be enough to finish on any system // bool signaled = cb.finished.wait (10 * 1000); expect (signaled, "timed out"); w.pauseAllThreadsAndWait (); int const count (cb.count.get ()); expectEquals (count, 0); }
void runTest() override { beginTest ("Basics"); Random r = getRandom(); int randomInt = r.nextInt(); int64 randomInt64 = r.nextInt64(); double randomDouble = r.nextDouble(); String randomString (createRandomWideCharString (r)); MemoryOutputStream mo; mo.writeInt (randomInt); mo.writeIntBigEndian (randomInt); mo.writeCompressedInt (randomInt); mo.writeString (randomString); mo.writeInt64 (randomInt64); mo.writeInt64BigEndian (randomInt64); mo.writeDouble (randomDouble); mo.writeDoubleBigEndian (randomDouble); MemoryInputStream mi (mo.getData(), mo.getDataSize(), false); expect (mi.readInt() == randomInt); expect (mi.readIntBigEndian() == randomInt); expect (mi.readCompressedInt() == randomInt); expectEquals (mi.readString(), randomString); expect (mi.readInt64() == randomInt64); expect (mi.readInt64BigEndian() == randomInt64); expect (mi.readDouble() == randomDouble); expect (mi.readDoubleBigEndian() == randomDouble); }
void runTest() { beginTest ("construction and parsing"); { expectThrowsType (OSCAddress (""), OSCFormatError); expectThrowsType (OSCAddress ("noleadingslash"), OSCFormatError); expectThrowsType (OSCAddress ("/notallowedchar "), OSCFormatError); expectThrowsType (OSCAddress ("/notallowedchar#"), OSCFormatError); expectThrowsType (OSCAddress ("/notallowedchar*"), OSCFormatError); expectThrowsType (OSCAddress ("/notallowedchar,"), OSCFormatError); expectThrowsType (OSCAddress ("/notallowedchar?"), OSCFormatError); expectThrowsType (OSCAddress ("/notallowedchar["), OSCFormatError); expectThrowsType (OSCAddress ("/notallowedchar]"), OSCFormatError); expectThrowsType (OSCAddress ("/notallowedchar{"), OSCFormatError); expectThrowsType (OSCAddress ("/notallowedchar}andsomemorechars"), OSCFormatError); expectThrowsType (OSCAddress (String::fromUTF8 ("/nonasciicharacter\xc3\xbc""blabla")), OSCFormatError); expectThrowsType (OSCAddress ("/nonprintableasciicharacter\t"), OSCFormatError); expectDoesNotThrow (OSCAddress ("/")); expectDoesNotThrow (OSCAddress ("/a")); expectDoesNotThrow (OSCAddress ("/a/")); expectDoesNotThrow (OSCAddress ("/a/bcd/")); expectDoesNotThrow (OSCAddress ("/abcd/efgh/ijkLMNOPq/666r/s")); expectDoesNotThrow (OSCAddress ("/allowedprintablecharacters!$%&()+-.^_`|~")); expectDoesNotThrow (OSCAddress ("/additonalslashes//will///be////ignored")); } beginTest ("conversion to/from String"); { OSCAddress address ("/this/is/a/very/long/address/"); expectEquals (address.toString(), String ("/this/is/a/very/long/address")); } }
/** * Test to determine if a very large WEBVTT Cue Id allows a *very* large * character input. This test floods the cue ID with characters, and should * fail with a LF mixed in with the random 5000+ character cue id. * * From http://dev.w3.org/html5/webvtt/#webvtt-cue-identifier (11/24/2012) * A WebVTT cue identifier is any sequence of one or more characters not * containing the substring "-->" (U+002D HYPHEN-MINUS, U+002D HYPHEN-MINUS, * U+003E GREATER-THAN SIGN), nor containing any U+000A LINE FEED (LF) * characters or U+000D CARRIAGE RETURN (CR) characters. * * Note: A WebVTT cue identifier can be used to reference a specific cue, for * example from script or CSS. */ TEST_F(CueIdLineEndings, LongStringLF) { loadVtt( "cue-ids/lineendings/long_string_lf.vtt", 1 ); ASSERT_LE( 1, errorCount() ); EXPECT_EQ( 1, errorCount() ); expectEquals( getError( 0 ), WEBVTT_CUE_INCOMPLETE, 4, 1 ); }
/** * Test if parser fails if there are two line ending characters (LF or CRLF) * between cue id and cue timestamp * * From http://dev.w3.org/html5/webvtt/#webvtt-cue-identifier (11/24/2012) * A WebVTT cue identifier is any sequence of one or more characters not * containing the substring "-->" (U+002D HYPHEN-MINUS, U+002D HYPHEN-MINUS, * U+003E GREATER-THAN SIGN), nor containing any U+000A LINE FEED (LF) * characters or U+000D CARRIAGE RETURN (CR) characters. * * Note: A WebVTT cue identifier can be used to reference a specific cue, for * example from script or CSS. */ TEST_F(CueIdLineEndings, TwoBetweenIdAndTimestamp) { loadVtt( "cue-ids/lineendings/two_between_id_and_timestamp.vtt", 1 ); ASSERT_LE( 1, errorCount() ); EXPECT_EQ( 1, errorCount() ); expectEquals( getError( 0 ), WEBVTT_CUE_INCOMPLETE, 4, 1 ); }
/** * Test if parser fails if there are no line endings (LF OR CRLF) between WEBVTT * signature and cue * * From http://dev.w3.org/html5/webvtt/#webvtt-cue-identifier (11/24/2012) * A WebVTT cue identifier is any sequence of one or more characters not * containing the substring "-->" (U+002D HYPHEN-MINUS, U+002D HYPHEN-MINUS, * U+003E GREATER-THAN SIGN), nor containing any U+000A LINE FEED (LF) * characters or U+000D CARRIAGE RETURN (CR) characters. * * Note: A WebVTT cue identifier can be used to reference a specific cue, for * example from script or CSS. */ TEST_F(CueIdLineEndings, MissingBetweenSignatureAndId) { loadVtt( "cue-ids/lineendings/missing_between_signature_and_id.vtt", 1 ); ASSERT_LE( 1, errorCount() ); EXPECT_EQ( 1, errorCount() ); expectEquals( getError( 0 ), WEBVTT_EXPECTED_EOL, 2, 1 ); }
/** * Test that the parser does not require a spacing character between cue end * time timestamp and settings. There cannot be four digits in a row after the * cue end time timestamp decimal. * * From http://dev.w3.org/html5/webvtt/#collect-webvtt-cue-timings-and-settings * (11/21/2012): * * 10. Collect a WebVTT timestamp. * 11. Let remainder be the trailing substring of input starting at position. * 12. Parse the WebVTT settings given by remainder for cue. * * From http://dev.w3.org/html5/webvtt/#collect-a-webvtt-timestamp (11/21/2012): * 14. Collect a sequence of characters that are ASCII digits, and let string be * the collected substring. * 15. If string is not exactly three characters in length, return an error and * abort these steps. */ TEST_F(CueSetting, BadDelimiter2) { loadVtt( "cue-settings/bad-delimiter2.vtt", 1 ); ASSERT_LE( 2, errorCount() ) << "This file should contain at least 2 error"; EXPECT_EQ( 2, errorCount() ) << "This file should contain 2 error"; /** * We're expecting a WEBVTT_EXPECTED_WHITESPACE error on the 24th column of * the 3rd line */ expectEquals( getError( 0 ), WEBVTT_EXPECTED_WHITESPACE, 3, 24 ); /** * Expecting WEBVTT_INVALID_CUESETTING on the 24th column of the 3rd line * (^line is not a valid keyword) */ expectEquals( getError( 1 ), WEBVTT_INVALID_CUESETTING, 3, 24 ); }
/** * Test that the parser does not require a spacing character between cue end * time timestamp and settings. There cannot be four digits in a row after the * cue end time timestamp decimal. * * From http://dev.w3.org/html5/webvtt/#collect-webvtt-cue-timings-and-settings * (11/21/2012): * * 10. Collect a WebVTT timestamp. * 11. Let remainder be the trailing substring of input starting at position. * 12. Parse the WebVTT settings given by remainder for cue. * * From http://dev.w3.org/html5/webvtt/#collect-a-webvtt-timestamp (11/21/2012): * 14. Collect a sequence of characters that are ASCII digits, and let string be * the collected substring. * 15. If string is not exactly three characters in length, return an error and * abort these steps. */ TEST_F(CueSetting, DigitDelimiter) { loadVtt( "cue-settings/digit-delimiter.vtt", 1 ); ASSERT_LE( 3, errorCount() ) << "This file should contain at least 3 error"; EXPECT_EQ( 3, errorCount() ) << "This file should contain 3 error"; /** * We're expecting a WEBVTT_MALFORMED_TIMESTAMP error on the 3rd line. */ expectEquals( getError( 0 ), WEBVTT_MALFORMED_TIMESTAMP, 3, 15 ); /** * Expecting WEBVTT_EXPECTED_WHITESPACE at the 25th column of the 3rd line */ expectEquals( getError( 1 ), WEBVTT_EXPECTED_WHITESPACE, 3, 25 ); /** * Expecting WEBVTT_INVALID_CUESETTING at the 25th column of the 3rd line */ expectEquals( getError( 2 ), WEBVTT_INVALID_CUESETTING, 3, 25 ); }
/** * Test that the parser does not require a spacing character between cue end * time timestamp and settings. There cannot be four digits in a row after the * cue end time timestamp decimal. * * From http://dev.w3.org/html5/webvtt/#collect-webvtt-cue-timings-and-settings * (11/21/2012): * * 10. Collect a WebVTT timestamp. * 11. Let remainder be the trailing substring of input starting at position. * 12. Parse the WebVTT settings given by remainder for cue. * * From http://dev.w3.org/html5/webvtt/#collect-a-webvtt-timestamp (11/21/2012): * 14. Collect a sequence of characters that are ASCII digits, and let string be * the collected substring. * 15. If string is not exactly three characters in length, return an error and * abort these steps. */ TEST_F(CueSetting, NoDelimiter) { loadVtt( "cue-settings/no-delimiter.vtt", 1 ); ASSERT_LE( 1, errorCount() ) << "This file should contain at least 1 error"; EXPECT_EQ( 1, errorCount() ) << "This file should contain 1 error"; /** * We're expecting a WEBVTT_EXPECTED_WHITESPACE error on the 24th column of * the 3rd line */ expectEquals( getError( 0 ), WEBVTT_EXPECTED_WHITESPACE, 3, 24 ); }
static int utilTest(void) { expectEquals(anmatUtilMax(5, 6), 6); expectEquals(anmatUtilMax(5.5, 5.6), 5.6); expectEquals(anmatUtilMax(5.0, 5.0 + .001), 5.0 + .001); expectEquals(anmatUtilMax(-1, 1), 1); expectEquals(anmatUtilAbs(5), 5); expectEquals(anmatUtilAbs(5.4321), 5.4321); expectEquals(anmatUtilAbs(-5.4321), 5.4321); expectEquals(anmatUtilAbs(0), 0); expectEquals(anmatUtilAbs(-0.1), 0.1); expect(anmatUtilNeighborhood(1, 1.5, .5)); expect(anmatUtilNeighborhood(1, 1.5, .75)); expect(anmatUtilNeighborhood(-1, 2, 3)); expect(anmatUtilNeighborhood(-1, 2, 3.1)); return 0; }
/** * Test that the keyword is case-sensitive. * * http://dev.w3.org/html5/webvtt/#parse-the-webvtt-settings (11/27/2012): * 4. Run the appropriate substeps that apply for the value of name, as follows: * If name is a case-sensitive match for "vertical" ... * If name is a case-sensitive match for "line" ... * If name is a case-sensitive match for "position" ... * If name is a case-sensitive match for "size" ... * If name is a case-sensitive match for "align" ... * 5. Next setting: Continue to the next token, if any. */ TEST_F(CueSettingAlign, UppercaseKeyword) { loadVtt( "cue-settings/align/uppercase-keyword.vtt", 1 ); const Error &err = getError( 0 ); /** * Align should be "middle" because the malformed setting should be skipped * and "middle" is default. */ ASSERT_TRUE( getCue( 0 ).isAlignedToMiddle() ); /** * We're expecting a WEBVTT_INVALID_CUESETTING error on the 25th column of the * 3rd line */ expectEquals( getError( 0 ), WEBVTT_INVALID_CUESETTING, 3, 25 ); }
/** * Test that the parser requires a colon. * * http://dev.w3.org/html5/webvtt/#parse-the-webvtt-settings (11/27/2012): * 1. If setting does not contain a U+003A COLON character (:), or if the first * U+003A COLON character (:) in setting is either the first or last * character of setting, then jump to the step labeled next setting. * 5. Next setting: Continue to the next token, if any. */ TEST_F(CueSettingAlign, BadDelimiter) { loadVtt( "cue-settings/align/bad-delimiter.vtt", 1 ); ASSERT_EQ( 1, errorCount() ); /** * Align should be "middle" because the malformed setting should be skipped * and "middle" is default. */ ASSERT_TRUE( getCue( 0 ).isAlignedToMiddle() ); /** * We're expecting a WEBVTT_INVALID_CUESETTING error on the 25th column of the 3rd line */ expectEquals( getError( 0 ), WEBVTT_INVALID_CUESETTING, 3, 25 ); }
static int rxOverflowTest(void) { uint8_t i, packet[64], macQueueSize; uint32_t value = 0xFFFFFFFF; SdlPacket reallyPacket; // Destination address of SDL_MAC_ADDRESS_BROADCAST so we will // put it in our queue. packet[8] = 0xFF; packet[9] = 0xFF; packet[10] = 0xFF; packet[11] = 0xFF; // MAC RX Overflow should be 0 at this point. expect(sdlCounterValue(SDL_COUNTER_MAC_RX_OVERFLOW, &value)); expectEquals(value, 0); // If we receive more than the mac queue can handle, then we should // get a SDL_COUNTER_MAC_RX_OVERFLOW counter increment. // Keep this macQueueSize value inline with the same one in mac.c! macQueueSize = 5; for (i = 0; i < macQueueSize; i ++) { expect(sdlCounterValue(SDL_COUNTER_MAC_RX_OVERFLOW, &value)); expectEquals(value, 0); phyReceiveIsr(packet, SDL_MAC_PDU_LEN); } for (i = 1; i < 5; i ++) { expect(sdlCounterValue(SDL_COUNTER_MAC_RX_OVERFLOW, &value)); expectEquals(value, i); phyReceiveIsr(packet, SDL_MAC_PDU_LEN); } // Clear the counter. expect(sdlCounterClear(SDL_COUNTER_MAC_RX_OVERFLOW)); expect(sdlCounterValue(SDL_COUNTER_MAC_RX_OVERFLOW, &value)); expectEquals(value, 0); // If we take a packet off the queue... expectEquals(sdlMacReceive(&reallyPacket), SDL_SUCCESS); // ...then we should have room to add one... phyReceiveIsr(packet, SDL_MAC_PDU_LEN); expect(sdlCounterValue(SDL_COUNTER_MAC_RX_OVERFLOW, &value)); expectEquals(value, 0); // ...but then go back to our overflow stuff... phyReceiveIsr(packet, SDL_MAC_PDU_LEN); expect(sdlCounterValue(SDL_COUNTER_MAC_RX_OVERFLOW, &value)); expectEquals(value, 1); return 0; }
/** * Test what happens when there isn't a matching value for the setting align. * * http://dev.w3.org/html5/webvtt/#parse-the-webvtt-settings (11/27/2012): * 4. Run the appropriate substeps that apply for the value of name, as follows: * If name is a case-sensitive match for "align" * 1. If value is a case-sensitive match for the string "start", ... * 2. If value is a case-sensitive match for the string "middle", ... * 3. If value is a case-sensitive match for the string "end", ... * 4. If value is a case-sensitive match for the string "left", ... * 5. If value is a case-sensitive match for the string "right", ... * 5. Next setting: Continue to the next token, if any. */ TEST_F(CueSettingAlign, BadValue) { loadVtt( "cue-settings/align/bad-value.vtt", 1 ); ASSERT_LE( 1, errorCount() ); EXPECT_EQ( 1, errorCount() ); /** * Align should be "middle" because the malformed setting should be skipped * and "middle" is default. */ expectDefaultAlignSetting( getCue( 0 ) ); /** * We're expecting a WEBVTT_ALIGN_BAD_VALUE error on the 25th column of the 3rd line */ expectEquals( getError( 0 ), WEBVTT_ALIGN_BAD_VALUE, 3, 25 ); }
/** * Verify the parser accepts duplicate settings. * * From http://dev.w3.org/html5/webvtt/#parse-the-webvtt-settings (11/27/2012): * * 1. Let settings be the result of splitting input on spaces. * 2. For each token setting in the list settings... */ TEST_F(CueSetting, SameCueSetting) { loadVtt( "cue-settings/2-same-settings.vtt", 1 ); ASSERT_LE( 1, errorCount() ) << "This file should contain at least 1 error"; EXPECT_EQ( 1, errorCount() ) << "This file should contain 1 error"; /** * Parser will successfully parse duplicate settings so there will be no * error. The settings are parsed in order so that the right most (last in * the list) one is used. */ ASSERT_TRUE( getCue( 0 ).isVerticalRightToLeft() ); /** * We're expecting a WEBVTT_VERTICAL_ALREADY_SET error on the 37th column of * the 3rd line We can probably make this smarter, like * WEBVTT_EXPECTED_CUESETTING_DELIMITER or something */ expectEquals( getError( 0 ), WEBVTT_VERTICAL_ALREADY_SET, 3, 37 ); }
/** * Test that the parser takes everything to the right of the first colon in a * setting. * * From http://dev.w3.org/html5/webvtt/#parse-the-webvtt-settings (11/27/2012): * * 1. Let settings be the result of splitting input on spaces. * 2. For each token setting in the list settings... * 3. Let value be the trailing substring of setting starting from the * character immediately after the first U+003A COLON character (:) in that * string. */ TEST_F(CueSetting, BadDelimiter) { loadVtt( "cue-settings/bad-delimiter.vtt", 1 ); ASSERT_LE( 1, errorCount() ) << "This file should contain at least 1 error"; EXPECT_EQ( 1, errorCount() ) << "This file should contain 1 error"; /** * The parser should try to use "vertical" as keyword and "lr;line:50%" as * value. Writing direction should "horizontal" because the malformed setting * should be skipped and "horizontal" is default. */ expectDefaultVerticalSetting( getCue( 0 ) ); /** * We're expecting a WEBVTT_VERTICAL_BAD_VALUE error on the 34th column of * the 3rd line (Beginning of value token) */ expectEquals( getError( 0 ), WEBVTT_VERTICAL_BAD_VALUE, 3, 25 ); }
void runTest() override { beginTest ("comparison operator"); { MPEValue value1 = MPEValue::from7BitInt (7); MPEValue value2 = MPEValue::from7BitInt (7); MPEValue value3 = MPEValue::from7BitInt (8); expect (value1 == value1); expect (value1 == value2); expect (value1 != value3); } beginTest ("special values"); { expectEquals (MPEValue::minValue().as7BitInt(), 0); expectEquals (MPEValue::minValue().as14BitInt(), 0); expectEquals (MPEValue::centreValue().as7BitInt(), 64); expectEquals (MPEValue::centreValue().as14BitInt(), 8192); expectEquals (MPEValue::maxValue().as7BitInt(), 127); expectEquals (MPEValue::maxValue().as14BitInt(), 16383); } beginTest ("zero/minimum value"); { expectValuesConsistent (MPEValue::from7BitInt (0), 0, 0, -1.0f, 0.0f); expectValuesConsistent (MPEValue::from14BitInt (0), 0, 0, -1.0f, 0.0f); } beginTest ("maximum value"); { expectValuesConsistent (MPEValue::from7BitInt (127), 127, 16383, 1.0f, 1.0f); expectValuesConsistent (MPEValue::from14BitInt (16383), 127, 16383, 1.0f, 1.0f); } beginTest ("centre value"); { expectValuesConsistent (MPEValue::from7BitInt (64), 64, 8192, 0.0f, 0.5f); expectValuesConsistent (MPEValue::from14BitInt (8192), 64, 8192, 0.0f, 0.5f); } beginTest ("value halfway between min and centre"); { expectValuesConsistent (MPEValue::from7BitInt (32), 32, 4096, -0.5f, 0.25f); expectValuesConsistent (MPEValue::from14BitInt (4096), 32, 4096, -0.5f, 0.25f); } }
void MonitorTests::callBackTest() { beginTest("CallBack Test"); Monitor monitor; monitor.startMonitoring(); ScopedPointer<SocketListener> listener = new SocketListener(); listener->initializeSockets(40780, &monitor, "quark"); pool->addJob(listener, false); while(pool->getNumJobs() > 0 ) { Thread::sleep(5); } monitor.stop(); expectEquals(true, listener->was_informed); }
int loopbackTest(void) { uint16_t first, second; expect(sdlMacAddress(&source) == SDL_SUCCESS); // If we send something to ourself... expect(sdlMacTransmit(SDL_PACKET_TYPE_DATA, source, data, dataBufferLength) == SDL_SUCCESS); // ...then we should be able to receive it...right? expect(sdlMacReceive(&packet) == SDL_SUCCESS); expect(packet.type == SDL_PACKET_TYPE_DATA); expect(packet.source == source); expect(packet.destination == source); expect(!memcmp(packet.data, data, dataBufferLength)); expect(packet.dataLength == dataBufferLength); first = packet.sequence; // TX + RX again. expectEquals(sdlMacTransmit(SDL_PACKET_TYPE_DATA, source, data, dataBufferLength), SDL_SUCCESS); expectEquals(sdlMacReceive(&packet), SDL_SUCCESS); expectEquals(packet.type, SDL_PACKET_TYPE_DATA); expectEquals(packet.source, source); expectEquals(packet.destination, source); expect(!memcmp(packet.data, data, dataBufferLength)); expectEquals(packet.dataLength, dataBufferLength); second = packet.sequence; // The sequence numbers should be different. expect(second > first); // After, the SDL should be empty. expect(sdlMacReceive(&packet) == SDL_MAC_EMPTY); return 0; }
void testDiff (const String& a, const String& b) { TextDiff diff (a, b); const String result (diff.appliedTo (a)); expectEquals (result, b); }
void MonitorTests::firstTest() { beginTest("Testing The Tester"); expect(true); expectEquals(true, !false); }
void runTest() override { beginTest ("initialisation"); { { MPEZone zone (1, 10); expectEquals (zone.getMasterChannel(), 1); expectEquals (zone.getNumNoteChannels(), 10); expectEquals (zone.getFirstNoteChannel(), 2); expectEquals (zone.getLastNoteChannel(), 11); expectEquals (zone.getPerNotePitchbendRange(), 48); expectEquals (zone.getMasterPitchbendRange(), 2); expect (zone.isUsingChannel (1)); expect (zone.isUsingChannel (2)); expect (zone.isUsingChannel (10)); expect (zone.isUsingChannel (11)); expect (! zone.isUsingChannel (12)); expect (! zone.isUsingChannel (16)); expect (! zone.isUsingChannelAsNoteChannel (1)); expect (zone.isUsingChannelAsNoteChannel (2)); expect (zone.isUsingChannelAsNoteChannel (10)); expect (zone.isUsingChannelAsNoteChannel (11)); expect (! zone.isUsingChannelAsNoteChannel (12)); expect (! zone.isUsingChannelAsNoteChannel (16)); } { MPEZone zone (5, 4); expectEquals (zone.getMasterChannel(), 5); expectEquals (zone.getNumNoteChannels(), 4); expectEquals (zone.getFirstNoteChannel(), 6); expectEquals (zone.getLastNoteChannel(), 9); expectEquals (zone.getPerNotePitchbendRange(), 48); expectEquals (zone.getMasterPitchbendRange(), 2); expect (! zone.isUsingChannel (1)); expect (! zone.isUsingChannel (4)); expect (zone.isUsingChannel (5)); expect (zone.isUsingChannel (6)); expect (zone.isUsingChannel (8)); expect (zone.isUsingChannel (9)); expect (! zone.isUsingChannel (10)); expect (! zone.isUsingChannel (16)); expect (! zone.isUsingChannelAsNoteChannel (5)); expect (zone.isUsingChannelAsNoteChannel (6)); expect (zone.isUsingChannelAsNoteChannel (8)); expect (zone.isUsingChannelAsNoteChannel (9)); expect (! zone.isUsingChannelAsNoteChannel (10)); } } beginTest ("getNoteChannelRange"); { MPEZone zone (2, 10); Range<int> noteChannelRange = zone.getNoteChannelRange(); expectEquals (noteChannelRange.getStart(), 3); expectEquals (noteChannelRange.getEnd(), 13); } beginTest ("setting master pitchbend range"); { MPEZone zone (1, 10); zone.setMasterPitchbendRange (96); expectEquals (zone.getMasterPitchbendRange(), 96); zone.setMasterPitchbendRange (0); expectEquals (zone.getMasterPitchbendRange(), 0); expectEquals (zone.getPerNotePitchbendRange(), 48); } beginTest ("setting per-note pitchbend range"); { MPEZone zone (1, 10); zone.setPerNotePitchbendRange (96); expectEquals (zone.getPerNotePitchbendRange(), 96); zone.setPerNotePitchbendRange (0); expectEquals (zone.getPerNotePitchbendRange(), 0); expectEquals (zone.getMasterPitchbendRange(), 2); } beginTest ("checking overlap"); { testOverlapsWith (1, 10, 1, 10, true); testOverlapsWith (1, 4, 6, 3, false); testOverlapsWith (1, 4, 8, 3, false); testOverlapsWith (2, 10, 2, 8, true); testOverlapsWith (1, 10, 3, 2, true); testOverlapsWith (3, 10, 5, 9, true); } beginTest ("truncating"); { testTruncateToFit (1, 10, 3, 10, true, 1, 1); testTruncateToFit (3, 10, 1, 10, false, 3, 10); testTruncateToFit (1, 10, 5, 8, true, 1, 3); testTruncateToFit (5, 8, 1, 10, false, 5, 8); testTruncateToFit (1, 10, 4, 3, true, 1, 2); testTruncateToFit (4, 3, 1, 10, false, 4, 3); testTruncateToFit (1, 3, 5, 3, true, 1, 3); testTruncateToFit (5, 3, 1, 3, false, 5, 3); testTruncateToFit (1, 3, 7, 3, true, 1, 3); testTruncateToFit (7, 3, 1, 3, false, 7, 3); testTruncateToFit (1, 10, 2, 10, false, 1, 10); testTruncateToFit (2, 10, 1, 10, false, 2, 10); } }