8000 Tests for stamp_dict · postgrespro/libblobstamper@71c7f51 · GitHub
[go: up one dir, main page]

Skip to content 8000

Commit 71c7f51

Browse files
Tests for stamp_dict
1 parent 2f3fe32 commit 71c7f51

File tree

4 files changed

+58
-3
lines changed

4 files changed

+58
-3
lines changed

blobstamper/stamp_dict.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
#include <limits.h>
66

7+
#include "blob.h"
8+
#include "stamp.h"
9+
#include "stamp_atomic.h"
710
#include "dict.h"
811

912
class StampDict: public StampGeneric

t/120-stamp_dict.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#include <string.h>
2+
3+
#include <exception>
4+
#include <string>
5+
#include <cstdlib>
6+
#define WANT_TEST_EXTRAS
7+
#include <tap++/tap++.h>
8+
9+
#include "blobstamper/dict.h"
10+
#include "blobstamper/stamp_dict.h"
11+
12+
class DictTest : public DictBase
13+
{
14+
public:
15+
DictTest();
16+
};
17+
18+
DictTest::DictTest()
19+
{
20+
data = {"one","two","three","four"};
21+
}
22+
23+
using namespace TAP;
24+
25+
/* Test that dict works as expected*/
26+
unsigned char sample[]={0,63,64,255};
27+
28+
int
29+
main()
30+
{
31+
TEST_START(4);
32+
{ /* 1..4 */
33+
DictTest dict;
34+
StampDict stamp(dict);
35+
Blob blob((char *) sample, 4);
36+
std::string s;
37+
38+
s = blob.ShiftSingleStampStr(stamp);
39+
is(s, "one", "0 stamps as first element of dict");
40+
41+
s = blob.ShiftSingleStampStr(stamp);
42+
is(s, "one", "63 still stamps as first element of dict, when dict has only four elements");
43+
44+
s = blob.ShiftSingleStampStr(stamp);
45+
is(s, "two", "64 stamps as second element of dict");
46+
47+
s = blob.ShiftSingleStampStr(stamp);
48+
is(s, "four", "255 stamps as last (fourth) element of dict");
49+
50+
}
51+
TEST_END;
52+
}

t/200-dict.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ main()
3030

3131
{ /* 1..2 */
3232
DictTest dict;
33-
ok(dict.size() == 3,"Dict size");
34-
ok(dict.get(1) == "two","Dict content");
33+
is(dict.size(), 3,"Dict size");
34+
is(dict.get(1), "two","Dict content");
3535
}
3636

3737
TEST_END;

t/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ DEBUG := -ggdb3 -DDEBUG
66
CXXFLAGS := $(DEBUG) $(WARNINGS) -fPIC
77
PREFIX := /usr/local
88
LIBRARY_VAR := LD_LIBRARY_PATH
9-
TEST_GOALS := ./00-sanity.t ./001-blob-generic.t ./100-stamp-base.t ./110-stamp-atomic.t ./200-dict.t ./300-galley.t ./500-stamp-pg-type-geo.t ./700-wrapper-pg-type-geo.t
9+
TEST_GOALS := ./00-sanity.t ./001-blob-generic.t ./100-stamp-base.t ./110-stamp-atomic.t ./120-stamp_dict.t ./200-dict.t ./300-galley.t ./500-stamp-pg-type-geo.t ./700-wrapper-pg-type-geo.t
1010

1111
all: build-libtappp $(TEST_GOALS)
1212

0 commit comments

Comments
 (0)
0