Skip to content

Commit 6e0ee5a

Browse files
author
Pierre-Alexandre Meyer
committed
test: make tests run via `make check'
Signed-off-by: Pierre-Alexandre Meyer <pierre@ning.com>
1 parent 5f6dd84 commit 6e0ee5a

File tree

7 files changed

+65
-19
lines changed

7 files changed

+65
-19
lines changed

README.rdoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ To boostrap the build (you need autotools):
1010

1111
cd c/ && bash build.sh
1212

13-
You can then build via `make'.
13+
You can then build via `make' and run tests via `make check'.
1414

1515
By default, the build produces multiple artifacts:
1616

c/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ AUTOMAKE_OPTIONS = subdir-objects
22
ACLOCAL_AMFLAGS = ${ACLOCAL_FLAGS}
33

44
SUBDIRS = src test
5+
6+
TESTS = test/smile_tests

c/test/Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
AM_CPPFLAGS = -I$(top_srcdir)
22
noinst_PROGRAMS = smile_tests
33

4-
smile_tests_SOURCES = test_decode.c
4+
smile_tests_SOURCES = smile_tests.c test_varint.c test_decode.c
55
smile_tests_LDADD = ../src/libsmile_decode-1.0.la -lsmile_decode-1.0

c/test/smile_tests.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2011 Pierre-Alexandre Meyer
3+
*
4+
* Pierre-Alexandre Meyer licenses this file to you under the Apache License,
5+
* version 2.0 (the "License"); you may not use this file except in compliance
6+
* with the License. You may obtain a copy of the License at:
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations
14+
* under the License.
15+
*/
16+
17+
#include <stdio.h>
18+
#include <stdlib.h>
19+
#include <time.h>
20+
21+
int main()
22+
{
23+
clock_t start, end;
24+
25+
printf("-------------------------------------------------------\n");
26+
printf(" T E S T S\n");
27+
printf("-------------------------------------------------------\n");
28+
printf("Running TestSuite\n");
29+
30+
start = clock();
31+
32+
test_varint();
33+
test_zigzag();
34+
test_decode();
35+
36+
end = clock();
37+
printf("Tests run: %d, Time elapsed: %f sec\n", 3, ((double) (end - start)) / CLOCKS_PER_SEC);
38+
exit(0);
39+
}

c/test/smile_tests.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#ifndef _SMILE_TESTS_H_
2+
#define _SMILE_TESTS_H_
3+
4+
#endif

c/test/test_decode.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <stdio.h>
1919
#include <stdlib.h>
2020

21+
#include "smile_tests.h"
2122
#include "../src/api.h"
2223
#include "../src/smile_decode.h"
2324
#include "../src/smile_utils.h"
@@ -51,7 +52,7 @@ inline void noop()
5152
inline void number(long number)
5253
{
5354
// TODO
54-
printf("%lu\n", number);
55+
//printf("%lu\n", number);
5556
}
5657

5758
static char* expected_string = NULL;
@@ -83,8 +84,7 @@ struct content_handler handler = {
8384
.characters = string
8485
};
8586

86-
87-
void test_decode()
87+
void test_decode_smile()
8888
{
8989
// Header + 1
9090
u8* ip = data + 5;
@@ -120,10 +120,8 @@ void test_decode()
120120
smile_decode_value((u8**) &ip, &handler);
121121
}
122122

123-
int main()
123+
void test_decode()
124124
{
125-
test_decode();
126-
127-
printf("Tests passed: %d assertions run.\n", pass);
128-
exit(0);
125+
test_decode_smile();
126+
printf("decode tests run: %d assertions passed\n", pass);
129127
}

c/test/test_varint.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616

1717
#include <errno.h>
1818
#include <stdio.h>
19+
#include <stdlib.h>
1920

21+
#include "smile_tests.h"
2022
#include "../src/api.h"
2123
#include "../src/smile_utils.h"
2224

@@ -30,15 +32,19 @@ static int pass = 0;
3032
pass++; \
3133
}
3234

33-
void test_varint()
35+
void test_number_encoding()
3436
{
3537
u8 buf[2];
3638
buf[0] = 0x02;
3739
buf[1] = 0xAC;
3840

39-
// Standard example, see
40-
// http://code.google.com/apis/protocolbuffers/docs/encoding.html#varints
41-
ASSERT_EQUAL(300, varint_decode_buffer(buf));
41+
// 01 7c a0 should be 8080 (0x1F90)
42+
// 0x 0111 1100 1010 0000
43+
// 111 1100 010 0000
44+
// 11 1110 0010 0000
45+
int i = 0x17ca0;
46+
//printf("0x%X\n", ZZ_DECODE(varint_decode_buffer(&i)));
47+
//ASSERT_EQUAL(300, varint_decode_buffer(0x017ca0));
4248
}
4349

4450
void test_zigzag()
@@ -51,11 +57,8 @@ void test_zigzag()
5157
ASSERT_EQUAL(-2147483648, ZZ_DECODE(4294967295))
5258
}
5359

54-
int main()
60+
void test_varint()
5561
{
56-
//test_varint();
5762
test_zigzag();
58-
59-
printf("Tests passed: %d assertions run.\n", pass);
60-
exit(0);
63+
printf("varint tests run: %d assertions passed\n", pass);
6164
}

0 commit comments

Comments
 (0)