summaryrefslogtreecommitdiff
path: root/yapf/unittest/test_blob.h
blob: 5f266b0f77aec35e9f04bd09233920ce741a188f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/* $Id$ */

static int TestBlob1(bool silent)
{
	typedef CBlobT<int64> Blob;
	int res = 0;
	{
		Blob a;
		Blob b;
		CHECK_INT(0, a.IsEmpty(), true);
		CHECK_INT(1, a.Size(), 0);

		const int nItems = 10;

    {
		  for (int i = 1; i <= nItems; i++) {
			  a.Append(i);
			  CHECK_INT(2, a.IsEmpty(), false);
			  CHECK_INT(3, a.Size(), i);
		  }
    }

    {
		  for (int i = 1; i <= nItems; i++) {
			  CHECK_INT(4, *a.Data(i - 1), i);
		  }
    }
	}
	return res;
}

static int TestBlob2(bool silent)
{
	typedef CBlobT<CFsaItem> Blob;
	int res = 0;
	{
		Blob a;
		Blob b;
		CHECK_INT(0, a.IsEmpty(), true);
		CHECK_INT(1, a.Size(), 0);

		const int nItems = 10;

    {
		  for (int i = 1; i <= nItems; i++) {
			  a.Append(CFsaItem(i));
			  CHECK_INT(2, a.IsEmpty(), false);
			  CHECK_INT(3, a.Size(), i);
		  }
    }
    {
		  for (int i = 1; i <= nItems; i++) {
			  CHECK_INT(4, a.Data(i - 1)->i, i);
		  }
    }
		CHECK_INT(15, CFsaItem::NumInstances(), nItems);
	}
	CHECK_INT(16, CFsaItem::NumInstances(), 0);

	return res;
}