code clean up in basic tests
Change-Id: If53516597bfe3d667b02c9a8d5806ee9658a1372
diff --git a/tests/basic_test.c b/tests/basic_test.c
index 721b774..6ca6d2e 100644
--- a/tests/basic_test.c
+++ b/tests/basic_test.c
@@ -1,3 +1,4 @@
+#include <stddef.h>
#include <stdio.h>
#include <string.h>
#define __USE_XOPEN_EXTENDED
@@ -66,16 +67,24 @@
}
void test_writing() {
- char *tmp = tempnam(NULL, NULL);
+ char tmp_template[] = "/tmp/tmpfileXXXXXX";
+ int fd = mkstemp(tmp_template);
+ if (fd == -1) {
+ perror("mkstemp");
+ exit(EXIT_FAILURE);
+ }
+ close(fd);
+ char *tmp = strdup(tmp_template);
+
long size = 0;
int i;
- char *rocksdbfn = malloc(strlen(tmp)+strlen(".rocksdb"));
- strcpy (rocksdbfn, tmp);
+ char *rocksdbfn = malloc(strlen(tmp) + strlen(".rocksdb") + 1);
+ strcpy(rocksdbfn, tmp);
strcat(rocksdbfn, ".rocksdb");
COLLOCATORDB *cdb = open_collocatordb_for_write(rocksdbfn);
- char *vocabfn = malloc(strlen(tmp)+strlen(".vocab"));
+ char *vocabfn = malloc(strlen(tmp) + strlen(".vocab") + 1);
strcpy(vocabfn, tmp);
strcat(vocabfn, ".vocab");
FILE *h = fopen(vocabfn, "w");
@@ -85,7 +94,7 @@
fclose(h);
read_vocab(cdb, vocabfn);
inc_collocator(cdb, 0, 1, 4); size++;
- for (i=0; i < 1000; i++) {
+ for (i = 0; i < 1000; i++) {
inc_collocator(cdb, 0, 1, i % 5); size++;
inc_collocator(cdb, 0, 1, -i % 5); size++;
inc_collocator(cdb, 1, 0, i % 5); size++;
@@ -103,6 +112,7 @@
rmrf(rocksdbfn);
}
+
void test_version_function() {
char *version = get_version();
TEST_CHECK(strcmp(version, "1.3.2") == 0);