Esempio n. 1
0
void ObjectTransactiontestUnit::test_update()
{
  matador::object_store store;
  store.attach<person>("person");

  auto hans = store.insert(new person("Hans", matador::date(12, 3, 1980), 180));

  matador::transaction tr(store);

  try {
    tr.begin();


    UNIT_ASSERT_EQUAL(hans->height(), 180U, "height must be valid");
    hans->height(183);
    UNIT_ASSERT_EQUAL(hans->height(), 183U, "height must be valid");
    UNIT_ASSERT_GREATER(hans->id(), 0UL, "id must be valid");

    tr.commit();
  } catch (std::exception &) {
    UNIT_FAIL("shouldn't come here");
  }

  UNIT_ASSERT_EQUAL(hans->height(), 183U, "height must be valid");
  UNIT_ASSERT_GREATER(hans->id(), 0UL, "id must be valid");

  matador::object_view<person> pview(store);

  UNIT_ASSERT_FALSE(pview.empty(), "view must not be empty");
}
Esempio n. 2
0
void TPtrTest::TestIntrPtr() {
    {
        TIntrusivePtr<TOp> p, p2;
        TOp3 op3;
        {
            yvector<TIntrusivePtr<TOp> > f1;
            {
                yvector<TIntrusivePtr<TOp> > f2;
                f2.push_back(new TOp);
                p = new TOp;
                f2.push_back(p);
                Attach(&op3, &f2[1]);
                f1 = f2;
                UNIT_ASSERT_EQUAL(f1[0]->RefCount(), 2);
                UNIT_ASSERT_EQUAL(f1[1]->RefCount(), 3);
                UNIT_ASSERT_EQUAL(f1[1].Get(), op3.Op2.Get());
                UNIT_ASSERT_EQUAL(op3.Op2->RefCount(), 3);
                UNIT_ASSERT_EQUAL(op3.Op2->Op->RefCount(), 2);
                UNIT_ASSERT_EQUAL(TOp::Cnt, 4);
            }
            p2 = p;
        }
        UNIT_ASSERT_EQUAL(op3.Op2->RefCount(), 1);
        UNIT_ASSERT_EQUAL(op3.Op2->Op->RefCount(), 3);
        UNIT_ASSERT_EQUAL(TOp::Cnt, 3);
    }
    UNIT_ASSERT_EQUAL(TOp::Cnt, 0);
}
Esempio n. 3
0
void ObjectTransactiontestUnit::test_delete_rollback()
{
  matador::object_store store;
  store.attach<person>("person");

  auto hans = store.insert(new person("Hans", matador::date(12, 3, 1980), 180));

  UNIT_ASSERT_GREATER(hans->id(), 0UL, "id must be valid");

  matador::transaction tr(store);

  try {
    tr.begin();

    store.remove(hans);

    tr.rollback();
  } catch (std::exception &) {
    tr.rollback();
  }

  matador::object_view<person> pview(store);

  auto p = pview.front();
  UNIT_ASSERT_EQUAL(pview.size(), 1UL, "size must be one");

  UNIT_ASSERT_GREATER(p.id(), 0UL, "id must be valid");
  UNIT_ASSERT_FALSE(p.ptr() == nullptr, "object must be nullptr");
  UNIT_ASSERT_GREATER(p->id(), 0UL, "id must be valid");
  UNIT_ASSERT_EQUAL(p->name(), "Hans", "name must be 'Hans'");
}
Esempio n. 4
0
        inline void TestSwapClass() {
            TTest i(0);
            TTest j(1);

            DoSwap(i, j);

            UNIT_ASSERT_EQUAL(i.Val, 1);
            UNIT_ASSERT_EQUAL(j.Val, 0);
        }
Esempio n. 5
0
        inline void TestSwapPrimitive() {
            int i = 0;
            int j = 1;

            DoSwap(i, j);

            UNIT_ASSERT_EQUAL(i, 1);
            UNIT_ASSERT_EQUAL(j, 0);
        }
Esempio n. 6
0
void TPtrTest::TestCopyPtr() {
    TCopyPtr<A> a1(newA());
    {
        TCopyPtr<A> a2(newA());
        TCopyPtr<A> a3 = a2;
        UNIT_ASSERT_EQUAL(cnt, 3);

        a1 = a2;
        a2 = a3;
    }
    UNIT_ASSERT_EQUAL(cnt, 1);
    a1.Destroy();

    UNIT_ASSERT_EQUAL(cnt, 0);
}
Esempio n. 7
0
void ObjectTransactiontestUnit::test_nested()
{
  matador::object_store store;
  store.attach<person>("person");

  matador::transaction tr1(store);

  try {
    tr1.begin();

    auto hans = store.insert(new person("Hans", matador::date(12, 3, 1980), 180));

    UNIT_ASSERT_GREATER(hans->id(), 0UL, "id must be valid");

    tr1.commit();

    tr1.begin();

    UNIT_ASSERT_EQUAL(hans->height(), 180U, "height must be valid");
    hans->height(183);
    UNIT_ASSERT_EQUAL(hans->height(), 183U, "height must be valid");

    matador::transaction tr2(store);

    try {
      tr2.begin();

      UNIT_ASSERT_EQUAL(hans->height(), 183U, "height must be valid");
      hans->height(159);
      UNIT_ASSERT_EQUAL(hans->height(), 159U, "height must be valid");

      tr2.commit();
    } catch (std::exception &) {
      tr2.rollback();
    }

    tr1.commit();
  } catch (std::exception &) {
    tr1.rollback();
  }

  matador::object_view<person> pview(store);

  auto p = pview.front();

  UNIT_ASSERT_GREATER(p->id(), 0UL, "id must be valid");
  UNIT_ASSERT_EQUAL(p->name(), "Hans", "name must be 'Hans'");
}
Esempio n. 8
0
void ObjectTransactiontestUnit::test_foreign()
{
  matador::object_store store;
  store.attach<child>("child");
  store.attach<master>("master");

  auto ch1 = store.insert(new child("child 1"));
  auto m1 = store.insert(new master("m1"));
  m1->children = ch1;

  matador::transaction tr(store);

  try {
    tr.begin();

    matador::object_view<master> mview(store);

    m1 = mview.front();

    UNIT_ASSERT_TRUE(m1.ptr() != nullptr, "master must be valid");
    UNIT_ASSERT_TRUE(m1->children.ptr() != nullptr, "child must be valid");
    UNIT_ASSERT_EQUAL(m1->name, "m1", "name must be valid");

    UNIT_ASSERT_TRUE(store.is_removable(m1), "m1 must be removable");

    store.remove(m1);

    UNIT_ASSERT_TRUE(mview.empty(), "view must be empty");

    tr.commit();
  } catch (std::exception &) {
    tr.rollback();
  }
}
Esempio n. 9
0
void TPtrTest::TestHolderPtr() {
    {
        THolder<A> a1(newA());
        THolder<A> a2(a1.Release());
    }

    UNIT_ASSERT_EQUAL(cnt, 0);
}
Esempio n. 10
0
    inline void TestIt() {
        THolder<TClass> c(new (100) TClass);

        UNIT_ASSERT_EQUAL(c->AdditionalDataLength(), 100);

        //test segfault
        memset(c->AdditionalData(), 0, c->AdditionalDataLength());
    }
Esempio n. 11
0
void TPtrTest::TestTrulePtr() {
    {
        TAutoPtr<A> a1(newA());
        TAutoPtr<A> a2(a1);
        a1 = a2;
    }

    UNIT_ASSERT_EQUAL(cnt, 0);
}
Esempio n. 12
0
       inline void TestMtpTask() {
            TMtpTasksPool pool;

            TMtpTasksPool::TMtpTaskFromPoolRef task = pool.Acquire();
            TCheckTask checkTask(15, 3);

            checkTask.Process(task);

            UNIT_ASSERT_EQUAL(TStatCounter::Created(), TStatCounter::Proceed() + TStatCounter::Throws());
        }
Esempio n. 13
0
        inline void TestThreadId() {
            TIdTester tst;
            TThread thr(tst.DoRun, &tst);

            tst.Thr = &thr;

            thr.Start();
            thr.Join();

            UNIT_ASSERT_EQUAL(tst.Cur, tst.Real);
            UNIT_ASSERT(tst.Cur != 0);
        }
Esempio n. 14
0
void TPtrTest::TestLinkedPtr() {
    {
        TLinkedPtr<A> a1(newA());
        TLinkedPtr<A> a2(newA());
        TLinkedPtr<A> a3 = a2;

        a1 = a2;
        a2 = a3;
    }

    UNIT_ASSERT_EQUAL(cnt, 0);
}
Esempio n. 15
0
void TPtrTest::TestSimpleIntrPtr() {
    {
        TSimpleIntrusivePtr<A> a1(newA());
        TSimpleIntrusivePtr<A> a2(newA());
        TSimpleIntrusivePtr<A> a3 = a2;

        a1 = a2;
        a2 = a3;
    }

    UNIT_ASSERT_EQUAL(cnt, 0);
}
Esempio n. 16
0
	void MakeSlowCapturingTest(const char* regexp, const char* text, size_t position, bool ans, const ystring& captured = ystring(""), const Pire::Encoding& encoding = Pire::Encodings::Utf8())
	{
		Pire::SlowCapturingScanner sc = SlowCompile(regexp, position, encoding);
		SlowCapturingScanner::State st = RunRegexp(sc, text);
		SlowCapturingScanner::SingleState fin;
		bool ifCaptured = sc.GetCapture(st, fin);
		if (ans) {
			UNIT_ASSERT(ifCaptured);
			ystring answer(text, fin.GetBegin(), fin.GetEnd() - fin.GetBegin());
			UNIT_ASSERT_EQUAL(answer, captured);
		} else  {
			UNIT_ASSERT(!ifCaptured);
		}
	}
Esempio n. 17
0
        inline void TestMD5() {
            // echo -n 'qwertyuiopqwertyuiopasdfghjklasdfghjkl' | md5sum
            char b[] = "qwertyuiopqwertyuiopasdfghjklasdfghjkl";

            MD5 r;
            r.Update((const unsigned char*)b, 15);
            r.Update((const unsigned char*)b + 15, strlen(b) - 15);

            char rs[33];
            Stroka s(r.End(rs));
            s.to_lower();

            UNIT_ASSERT_EQUAL(s, Stroka("3ac00dd696b966fd74deee3c35a59d8f"));
        }
Esempio n. 18
0
        inline void TestFile() {
            Stroka s = NUnitTest::RandomString(1000000, 1);
            const Stroka tmpFile = "tmp";

            {
                TBufferedFileOutput fo(tmpFile);

                fo.Write(~s, +s);
            }

            char buf1[100];
            char buf2[100];

            UNIT_ASSERT_EQUAL(Stroka(MD5::File(~tmpFile, buf1)), Stroka(MD5::Data((const unsigned char*)~s, +s, buf2)));

            NFs::Remove(~tmpFile);
        }
Esempio n. 19
0
        inline void TestVirtualInheritance() {
            TStringStream ss;

            OUTS = &ss;

            class TA {
                public:
                    inline TA() {
                        *OUTS << "A";
                    }
            };

            class TB {
                public:
                    inline TB() {
                        *OUTS << "B";
                    }
            };

            class TC: public virtual TB, public virtual TA {
                public:
                    inline TC() {
                        *OUTS << "C";
                    }
            };

            class TD: public virtual TA {
                public:
                    inline TD() {
                        *OUTS << "D";
                    }
            };

            class TE: public TC, public TD {
                public:
                    inline TE() {
                        *OUTS << "E";
                    }
            };

            TE e;

            UNIT_ASSERT_EQUAL(ss.Str(), "BACDE");
        }
Esempio n. 20
0
 inline void TestSwap16() {
     UNIT_ASSERT_EQUAL((ui16)0x1234, SwapBytes((ui16)0x3412));
 }
Esempio n. 21
0
 inline void TestSwap32() {
     UNIT_ASSERT_EQUAL(0x12345678, SwapBytes(0x78563412));
 }
Esempio n. 22
0
 inline void TestSwap64() {
     UNIT_ASSERT_EQUAL(0x1234567890abcdefULL, SwapBytes((ui64)ULL(0xefcdab9078563412)));
 }
Esempio n. 23
0
 inline void TestNumberOfCpus() {
     UNIT_ASSERT(NSystemInfo::NumberOfCpus() > 0);
     UNIT_ASSERT_EQUAL(NSystemInfo::NumberOfCpus(), NSystemInfo::CachedNumberOfCpus());
 }