Skip to content

Commit 8d76056

Browse files
committed
Add basic test
1 parent 5eb233a commit 8d76056

File tree

4 files changed

+70
-2
lines changed

4 files changed

+70
-2
lines changed

.github/workflows/ci.yml

+8-1
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@ jobs:
1515
- name: Install dependencies
1616
run: |
1717
sudo apt-get update
18-
sudo apt-get install meson libbz2-dev
18+
sudo apt-get install meson libbz2-dev libglib2.0-dev
1919
- name: Checkout code
2020
uses: actions/checkout@v4
2121
- name: Setup build
2222
run: meson setup build
2323
- name: Build library
2424
run: meson compile -C build/
25+
- name: Run tests
26+
run: meson test -C build/
2527

2628
build-macos:
2729
name: Build (macOS)
@@ -36,6 +38,8 @@ jobs:
3638
run: meson setup build
3739
- name: Build library
3840
run: meson compile -C build/
41+
- name: Run tests
42+
run: meson test -C build/
3943

4044
build-windows:
4145
name: Build (Windows MINGW64)
@@ -52,9 +56,12 @@ jobs:
5256
mingw-w64-x86_64-toolchain
5357
mingw-w64-x86_64-meson
5458
mingw-w64-x86_64-bzip2
59+
mingw-w64-x86_64-glib2
5560
- name: Checkout code
5661
uses: actions/checkout@v4
5762
- name: Setup build
5863
run: meson setup build
5964
- name: Build library
6065
run: meson compile -C build/
66+
- name: Run tests
67+
run: meson test -C build/

meson.build

+5-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ cc = meson.get_compiler('c')
1111

1212
zlib_req = '>=1.2.0'
1313
bzip2_req = '>=1.0.0'
14+
glib_req = '>=2.64.0' # only used for tests
1415

1516
zlib_dep = dependency('zlib', version: zlib_req)
1617

@@ -21,4 +22,7 @@ if not bzip2_dep.found()
2122
bzip2_dep = cc.find_library('bz2', has_headers: 'bzlib.h')
2223
endif
2324

24-
subdir('src')
25+
glib_dep = dependency('glib-2.0', version: glib_req, required: false)
26+
27+
subdir('src')
28+
subdir('tests')

tests/meson.build

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
libfst_tests = [
2+
'write_and_read',
3+
]
4+
5+
foreach test : libfst_tests
6+
exe = executable(
7+
'test-' + test,
8+
test + '.c',
9+
dependencies: [libfst_dep, glib_dep],
10+
)
11+
12+
test(test, exe)
13+
endforeach

tests/write_and_read.c

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include <fstapi.h>
2+
#include <glib.h>
3+
4+
int main(int argc, char **argv)
5+
{
6+
// Write simple FST file
7+
8+
void *writer = fstWriterCreate("out.fst", 1);
9+
g_assert_true(writer != NULL);
10+
11+
fstHandle var = fstWriterCreateVar(writer, FST_VT_VCD_WIRE, FST_VD_IMPLICIT, 1, "var", 0);
12+
13+
fstWriterEmitTimeChange(writer, 0);
14+
fstWriterEmitValueChange(writer, var, "0");
15+
fstWriterEmitTimeChange(writer, 1);
16+
fstWriterEmitValueChange(writer, var, "1");
17+
fstWriterEmitTimeChange(writer, 2);
18+
19+
fstWriterClose(writer);
20+
21+
// Read generated FST file
22+
23+
void *reader = fstReaderOpen("out.fst");
24+
g_assert_true(reader != NULL);
25+
26+
g_assert_cmpint(fstReaderGetStartTime(reader), ==, 0);
27+
g_assert_cmpint(fstReaderGetEndTime(reader), ==, 2);
28+
g_assert_cmpint(fstReaderGetVarCount(reader), ==, 1);
29+
g_assert_cmpint(fstReaderGetScopeCount(reader), ==, 0);
30+
g_assert_cmpint(fstReaderGetAliasCount(reader), ==, 0);
31+
32+
struct fstHier *iter = fstReaderIterateHier(reader);
33+
g_assert_true(iter != NULL);
34+
g_assert_cmpint(iter->htyp, ==, FST_HT_VAR);
35+
g_assert_cmpstr(iter->u.var.name, ==, "var");
36+
g_assert_cmpint(iter->u.var.length, ==, 1);
37+
38+
iter = fstReaderIterateHier(reader);
39+
g_assert_true(iter == NULL);
40+
41+
fstReaderClose(reader);
42+
43+
return 0;
44+
}

0 commit comments

Comments
 (0)