Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3774639

Browse files
Add tests for sized_ptr and VLATO_ptr
1 parentdf9a681 commit3774639

File tree

3 files changed

+68
-2
lines changed

3 files changed

+68
-2
lines changed

‎t/050-sized_prt_and_vsato_ptr.cpp

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#include<exception>
2+
#include<string>
3+
#include<cstdlib>
4+
#defineWANT_TEST_EXTRAS
5+
#include<tap++/tap++.h>
6+
7+
#include"blobstamper/helpers.h"
8+
9+
usingnamespaceTAP;
10+
11+
12+
typedefstruct
13+
{
14+
float f;
15+
long l;
16+
char c;
17+
} FixedLengthObject;
18+
19+
typedefstruct
20+
{
21+
float f;
22+
long l;
23+
char c;
24+
shortint arr[];
25+
} VariableLengthObject;
26+
27+
28+
29+
intmain() {
30+
TEST_START(10);
31+
32+
// #tests for sized_ptr
33+
{/* 1..3*/
34+
long *l;
35+
size_t size =sizeof(long) *5;
36+
l = (long*)malloc(size);
37+
for(int i=0; i<5; i++)
38+
l[i]=i*100;
39+
sized_ptr<long>sp(l, size);
40+
41+
long * l2 = sp;
42+
is(l2[4],400,"Can use memory from sized poiner");
43+
ok(l2 == l,"It is actually same pointer");
44+
is(sp.size(),size,"Size is stored as expected");
45+
// free(l); /*Do not need to free it. sized_ptr will do it for you*/
46+
}
47+
{/* 4..10*/
48+
is(sizeof(FixedLengthObject),sizeof(VariableLengthObject),"sizes sainity check VLATO_prt expects this to be true");
49+
VLATO_ptr<VariableLengthObject,shortint>vp(5);
50+
is(vp.length(),5,"Number of elements is ok");
51+
is(vp.size(),sizeof(VariableLengthObject) +sizeof(shortint) *5,"Size of object is ok");
52+
VariableLengthObject *p1 = vp;
53+
p1->arr[4]=100;
54+
55+
sized_ptr<VariableLengthObject> sp = vp;// from now on vp does not exit
56+
VariableLengthObject *p2 = vp;
57+
ok(!p2,"now vp should not point anywere");
58+
is(sp.size(),sizeof(VariableLengthObject) +sizeof(shortint) *5,"Size of sized object is ok");
59+
60+
VariableLengthObject *p3 = sp;
61+
ok(p1 == p3,"Still same object");
62+
is(p3->arr[4],100,"stored data is in it's place");
63+
}
64+
TEST_END;
65+
}

‎t/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ PREFIX := /usr/local
88
LIBRARY_VAR := LD_LIBRARY_PATH
99
TEST_GOALS := ./00-sanity.t\
1010
./001-blob-generic.t\
11+
./050-sized_prt_and_vsato_ptr.t\
1112
./100-stamp-base.t\
1213
./110-stamp-arithm.t\
1314
./120-stamp_dict.t\

‎test_with_sanitizers.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/sh
22

3-
export CC=clang
4-
export CXX=clang++
3+
export CC=clang-11
4+
export CXX=clang++-11
55
export CFLAGS="-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=undefined"
66
export CXXFLAGS="-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=undefined"
77
export LDFLAGS="-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=undefined"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp