Beispiel #1
0
static void
test_homo_copy_ctor ()
{
    rw_info (0, __FILE__, __LINE__,
             "copy constructor (homogenous tuples)");

    std::tuple<> et1, et2 (et1);
    _RWSTD_UNUSED (et2);

    const int ci = std::rand ();
    const std::tuple<int> it1 (ci);
    std::tuple<int> it2 (it1);
    test (__LINE__, it2, ci);

    const std::tuple<const int>& ct1 = it1; // same as copy ctor
    std::tuple<const int> ct2 (ct1);
    test (__LINE__, ct2, ci);

    int i = ci;
    const std::tuple<int&> rt1 (i);
    std::tuple<int&> rt2 (rt1);
    test (__LINE__, rt2, ci);

    const std::tuple<std::tuple<int> > nt1 (it1);
    std::tuple<std::tuple<int> > nt2 (nt1);
    test (__LINE__, nt2, it1);

    const std::tuple<long, const char*> pt1 (1234567890L, "string");
    std::tuple<long, const char*> pt2 (pt1);
    test (__LINE__, pt2, 1234567890L, (const char*) "string");

    UserDefined ud (ci);
    const std::tuple<UserDefined> ut1 (ud);
    UserDefined::reset ();
    std::tuple<UserDefined> ut2 (ut1);
    ++UserDefined::expect.copy_ctor;
    test (__LINE__, ut2, ud);

    const std::tuple<bool, char, int, double, void*, UserDefined>
        bt1 (true, 'a', ci, 3.14159, (void* const) &i, ud);
    ++UserDefined::expect.move_ctor; // moved ud to bt1
    std::tuple<bool, char, int, double, void*, UserDefined> bt2 (bt1);
    ++UserDefined::expect.copy_ctor; // copied to bt2
    test (__LINE__, bt2, true, 'a', ci, 3.14159, (void* const) &i, ud);
}
Beispiel #2
0
static void
test_homo_move_ctor ()
{
    rw_info (0, __FILE__, __LINE__,
             "move constructor (homogenous tuples)");

    std::tuple<> et (std::tuple<> ()); _RWSTD_UNUSED (et);

    const int ci = std::rand ();

    std::tuple<int> it1 (ci);
    std::tuple<int> it2 (std::move (it1));
    test (__LINE__, it2, ci);

    std::tuple<const int> ct1 (ci);
    std::tuple<const int> ct2 = std::move (ct1);
    test (__LINE__, ct2, ci);

    std::tuple<std::tuple<int> > nt1 (it1);
    std::tuple<std::tuple<int> > nt2 = std::move (nt1);
    test (__LINE__, nt2, it1);

    std::tuple<long, const char*> pt1 (1234567890L, "string");
    std::tuple<long, const char*> pt2 (std::move (pt1));
    test (__LINE__, pt2, 1234567890L, (const char*) "string");

    const UserDefined ud (ci);
    std::tuple<UserDefined> ut1 (ud);
    UserDefined::reset ();
    std::tuple<UserDefined> ut2 (std::move (ut1));
    ++UserDefined::expect.move_ctor;
    test (__LINE__, ut2, ud);

    std::tuple<bool, char, int, double, void*, UserDefined>
        bt1 (true, 'a', ci, 3.14159, (void*) &ci, ud);
    ++UserDefined::expect.copy_ctor;
    std::tuple<bool, char, int, double, void*, UserDefined>
        bt2 (std::move (bt1));
    ++UserDefined::expect.move_ctor;
    test (__LINE__, bt2, true, 'a', ci, 3.14159, (void*) &ci, ud);
}
Beispiel #3
0
	void
	ReceiverTest::onData()
	{
		bool forMe = false;

		// Broadcast
		BroadcastTransmissionPtr bt(
			new BroadcastTransmission(
				wns::osi::PDUPtr(new wns::ldk::helper::FakePDU(100)),
				transmitter));

		forMe = receiver->onData(bt);
		CPPUNIT_ASSERT_EQUAL( 1, handler->cOnData );
		WNS_ASSERT_MAX_REL_ERROR( 0.1, handler->ber, 1E-10);
		CPPUNIT_ASSERT( forMe );

		// Unicast
		UnicastTransmissionPtr ut(
			new UnicastTransmission(
				wns::service::dll::UnicastAddress(2),
				wns::osi::PDUPtr(new wns::ldk::helper::FakePDU(100)),
				transmitter));

		forMe = receiver->onData(ut);
		CPPUNIT_ASSERT_EQUAL( 1, handler->cOnData );
		CPPUNIT_ASSERT( !forMe );

		UnicastTransmissionPtr ut2(
			new UnicastTransmission(
				wns::service::dll::UnicastAddress(1),
				wns::osi::PDUPtr(new wns::ldk::helper::FakePDU(100)),
				transmitter));

		forMe = receiver->onData(ut2);
		CPPUNIT_ASSERT_EQUAL( 2, handler->cOnData );
		CPPUNIT_ASSERT( forMe );
	}
Beispiel #4
0
static void
test_lt ()
{
    rw_info (0, __FILE__, __LINE__, "operator<");

    std::tuple<> nt1, nt2;
    TEST (!(nt1 < nt1));
    TEST (!(nt1 < nt2));

    std::tuple<int> it1 (1), it2 (2);
    TEST (!(it1 < it1));
    TEST (it1 < it2);

    UserDefined ud1 (1), ud2 (2);
    std::tuple<UserDefined> ut1 (ud1), ut2 (ud2);
    TEST (!(ut1 < ut1));
    TEST (ut1 < ut2);

    std::tuple<long, const char*> pt1 (1234L, "string");
    TEST (!(pt1 < pt1));
    std::tuple<long, const char*> pt2 (1235L, "string");
    TEST (pt1 < pt2);
    std::tuple<long, const char*> pt3 (1234L, "strings");
    TEST (pt1 < pt3);

    std::tuple<bool, char, int, double, void*, UserDefined>
        bt1 (true, 'a', 255, 3.14159, &nt1, ud1),
        bt2 (true, 'a', 256, 3.14159, &nt1, ud1),
        bt3 (true, 'a', 255, 3.14159, &nt1, ud2);
    rw_assert (!(bt1 < bt1), __FILE__, __LINE__,
               "bt1 < bt1, got true, expected false");
    rw_assert (bt1 < bt2, __FILE__, __LINE__,
               "bt1 < bt2, got false, expected true");
    rw_assert (bt1 < bt3, __FILE__, __LINE__,
               "bt1 < bt3, got false, expected true");
}
Beispiel #5
0
static void
test_eq ()
{
    rw_info (0, __FILE__, __LINE__, "operator==");

    std::tuple<> nt1, nt2;
    // special case
    rw_assert (nt1 == nt1, __FILE__, __LINE__,
               "nt1 == nt1, got false, expected true");

#undef TEST
#define TEST(expr)      \
    rw_assert (expr, __FILE__, __LINE__, #expr \
               "; got %b, expected %b", !(expr), expr)

    TEST (nt1 == nt2);

    std::tuple<int> it1 (1), it2 (1), it3 (2);
    TEST (it1 == it1);
    TEST (it1 == it2);
    TEST (!(it1 == it3));

    UserDefined ud1 (1), ud2 (2);
    std::tuple<UserDefined> ut1 (ud1), ut2 (ud1), ut3 (ud2);
    TEST (ut1 == ut1);
    TEST (ut1 == ut2);
    TEST (!(ut1 == ut3));

    std::tuple<bool, char, int, double, void*, UserDefined>
        bt1 (true, 'a', 255, 3.14159, &nt1, ud1),
        bt2 (true, 'a', 255, 3.14159, &nt1, ud1),
        bt3 (true, 'a', 256, 3.14159, &nt1, ud1);
    TEST (bt1 == bt1);
    TEST (bt1 == bt2);
    TEST (!(bt1 == bt3));
}
Beispiel #6
0
void RBBIAPITest::TestGetSetAdoptText()
{
    logln((UnicodeString)"Testing getText setText ");
    IcuTestErrorCode status(*this, "TestGetSetAdoptText");
    UnicodeString str1="first string.";
    UnicodeString str2="Second string.";
    LocalPointer<RuleBasedBreakIterator> charIter1((RuleBasedBreakIterator*)RuleBasedBreakIterator::createCharacterInstance(Locale::getDefault(), status));
    LocalPointer<RuleBasedBreakIterator> wordIter1((RuleBasedBreakIterator*)RuleBasedBreakIterator::createWordInstance(Locale::getDefault(), status));
    if(status.isFailure()){
        errcheckln(status, "Fail : in construction - %s", status.errorName());
            return;
    }


    CharacterIterator* text1= new StringCharacterIterator(str1);
    CharacterIterator* text1Clone = text1->clone();
    CharacterIterator* text2= new StringCharacterIterator(str2);
    CharacterIterator* text3= new StringCharacterIterator(str2, 3, 10, 3); //  "ond str"

    wordIter1->setText(str1);
    CharacterIterator *tci = &wordIter1->getText();
    UnicodeString      tstr;
    tci->getText(tstr);
    TEST_ASSERT(tstr == str1);
    if(wordIter1->current() != 0)
        errln((UnicodeString)"ERROR:1 setText did not set the iteration position to the beginning of the text, it is" + wordIter1->current() + (UnicodeString)"\n");

    wordIter1->next(2);

    wordIter1->setText(str2);
    if(wordIter1->current() != 0)
        errln((UnicodeString)"ERROR:2 setText did not reset the iteration position to the beginning of the text, it is" + wordIter1->current() + (UnicodeString)"\n");


    charIter1->adoptText(text1Clone);
    TEST_ASSERT(wordIter1->getText() != charIter1->getText());
    tci = &wordIter1->getText();
    tci->getText(tstr);
    TEST_ASSERT(tstr == str2);
    tci = &charIter1->getText();
    tci->getText(tstr);
    TEST_ASSERT(tstr == str1);


    LocalPointer<RuleBasedBreakIterator> rb((RuleBasedBreakIterator*)wordIter1->clone());
    rb->adoptText(text1);
    if(rb->getText() != *text1)
        errln((UnicodeString)"ERROR:1 error in adoptText ");
    rb->adoptText(text2);
    if(rb->getText() != *text2)
        errln((UnicodeString)"ERROR:2 error in adoptText ");

    // Adopt where iterator range is less than the entire orignal source string.
    //   (With the change of the break engine to working with UText internally,
    //    CharacterIterators starting at positions other than zero are not supported)
    rb->adoptText(text3);
    TEST_ASSERT(rb->preceding(2) == 0);
    TEST_ASSERT(rb->following(11) == BreakIterator::DONE);
    //if(rb->preceding(2) != 3) {
    //    errln((UnicodeString)"ERROR:3 error in adoptText ");
    //}
    //if(rb->following(11) != BreakIterator::DONE) {
    //    errln((UnicodeString)"ERROR:4 error in adoptText ");
    //}

    // UText API
    //
    //   Quick test to see if UText is working at all.
    //
    const char *s1 = "\x68\x65\x6C\x6C\x6F\x20\x77\x6F\x72\x6C\x64"; /* "hello world" in UTF-8 */
    const char *s2 = "\x73\x65\x65\x20\x79\x61"; /* "see ya" in UTF-8 */
    //                012345678901

    status.reset();
    LocalUTextPointer ut(utext_openUTF8(NULL, s1, -1, status));
    wordIter1->setText(ut.getAlias(), status);
    TEST_ASSERT_SUCCESS(status);

    int32_t pos;
    pos = wordIter1->first();
    TEST_ASSERT(pos==0);
    pos = wordIter1->next();
    TEST_ASSERT(pos==5);
    pos = wordIter1->next();
    TEST_ASSERT(pos==6);
    pos = wordIter1->next();
    TEST_ASSERT(pos==11);
    pos = wordIter1->next();
    TEST_ASSERT(pos==UBRK_DONE);

    status.reset();
    LocalUTextPointer ut2(utext_openUTF8(NULL, s2, -1, status));
    TEST_ASSERT_SUCCESS(status);
    wordIter1->setText(ut2.getAlias(), status);
    TEST_ASSERT_SUCCESS(status);

    pos = wordIter1->first();
    TEST_ASSERT(pos==0);
    pos = wordIter1->next();
    TEST_ASSERT(pos==3);
    pos = wordIter1->next();
    TEST_ASSERT(pos==4);

    pos = wordIter1->last();
    TEST_ASSERT(pos==6);
    pos = wordIter1->previous();
    TEST_ASSERT(pos==4);
    pos = wordIter1->previous();
    TEST_ASSERT(pos==3);
    pos = wordIter1->previous();
    TEST_ASSERT(pos==0);
    pos = wordIter1->previous();
    TEST_ASSERT(pos==UBRK_DONE);

    status.reset();
    UnicodeString sEmpty;
    LocalUTextPointer gut2(utext_openUnicodeString(NULL, &sEmpty, status));
    wordIter1->getUText(gut2.getAlias(), status);
    TEST_ASSERT_SUCCESS(status);
    status.reset();
}