Skip to content

Commit

Permalink
Moved assertions for external_transition test to test_driver.c.
Browse files Browse the repository at this point in the history
  • Loading branch information
clnhlzmn committed Mar 26, 2021
1 parent 1fd290e commit 7c67fa5
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import java.io.File
import java.util.concurrent.TimeUnit
import kotlin.test.assertEquals

class ExternalTransitionTest {

Expand Down Expand Up @@ -33,14 +34,14 @@ class ExternalTransitionTest {
.directory(File("./../test/external_transition"))
.command("make", "clean").start()
makeClean.waitFor(10, TimeUnit.SECONDS)
assertEquals(false, makeClean.isAlive)
assertEquals(0, makeClean.exitValue())

val make = ProcessBuilder()
.directory(File("./../test/external_transition"))
.command("make").start()
make.waitFor(10, TimeUnit.SECONDS)

File("./../test/external_transition/out/test_output.txt").reader().use {
Assertions.assertEquals(output, it.readLines())
}
assertEquals(false, make.isAlive)
assertEquals(0, make.exitValue())
}
}
63 changes: 48 additions & 15 deletions test/external_transition/test_driver.c
Original file line number Diff line number Diff line change
@@ -1,64 +1,97 @@

#include <stdio.h>
#include <assert.h>
#include <string.h>
#include "out/test.h"

FILE *output;
static const char *expected_output[] = {
"s1_entry",
"s1_s2_entry",
"s1_s2_e1_guard",
"s1_s2_exit",
"s1_exit",
"s1_entry",
"s1_s2_entry",
"s1_s2_e1_guard",
"s1_s2_exit",
"s1_exit",
"s1_entry",
"s1_s2_entry",
"s1_s2_e2_guard",
"s1_s2_exit",
"s1_s2_entry",
"s1_s2_e2_guard",
"s1_s2_exit",
"s1_s2_entry"
};

#define N_EVENTS (sizeof(expected_output) / sizeof(const char *))

static const char *actual_output[N_EVENTS];

static size_t output_index = 0;

#define PUSH_EVENT(e) do { \
assert(output_index < N_EVENTS); \
actual_output[output_index++] = e; \
} while (0)

int s1_s2_entry(struct test *self, struct test_event *event) {
(void)self; (void)event;
fprintf(output, "s1_s2_entry\n");
PUSH_EVENT("s1_s2_entry");
return 0;
}

static int guard = 0;

int s1_s2_e1_guard(struct test *self, struct test_event *event) {
(void)self; (void)event;
fprintf(output, "s1_s2_e1_guard\n");
PUSH_EVENT("s1_s2_e1_guard");
return guard;
}

int s1_s2_e2_guard(struct test *self, struct test_event *event) {
(void)self; (void)event;
fprintf(output, "s1_s2_e2_guard\n");
PUSH_EVENT("s1_s2_e2_guard");
return guard;
}

int s1_s2_e1_action(struct test *self, struct test_event *event) {
(void)self; (void)event;
fprintf(output, "s1_s2_e1_action\n");
PUSH_EVENT("s1_s2_e1_action");
return 0;
}

int s1_s2_exit(struct test *self, struct test_event *event) {
(void)self; (void)event;
fprintf(output, "s1_s2_exit\n");
PUSH_EVENT("s1_s2_exit");
return 0;
}

int s1_entry(struct test *self, struct test_event *event) {
(void)self; (void)event;
fprintf(output, "s1_entry\n");
PUSH_EVENT("s1_entry");
return 0;
}

int s1_exit(struct test *self, struct test_event *event) {
(void)self; (void)event;
fprintf(output, "s1_exit\n");
PUSH_EVENT("s1_exit");
return 0;
}

int main (void) {
output = fopen("out/test_output.txt", "w+");
struct test instance;
test_init(&instance); /*s1_entry, s1_s2_entry*/
test_process_event(&instance, &(struct test_event){.id = test_event_e1}); /*s1_s2_e1_guard, s1_s2_exit, s1_exit, s1_entry, s1_s2_entry*/
test_init(&instance);
test_process_event(&instance, &(struct test_event){.id = test_event_e1});
guard = 1;
test_process_event(&instance, &(struct test_event){.id = test_event_e1}); /*s1_s2_e1_guard, s1_s2_exit, s1_exit, s1_entry, s1_s2_entry*/
test_process_event(&instance, &(struct test_event){.id = test_event_e1});
guard = 0;
test_process_event(&instance, &(struct test_event){.id = test_event_e2}); /*s1_s2_e2_guard, s1_s2_exit, s1_s2_entry*/
test_process_event(&instance, &(struct test_event){.id = test_event_e2});
guard = 1;
test_process_event(&instance, &(struct test_event){.id = test_event_e2}); /*s1_s2_e2_guard, s1_s2_exit, s1_s2_entry*/
fclose(output);
test_process_event(&instance, &(struct test_event){.id = test_event_e2});
for (size_t i = 0; i < N_EVENTS; ++i) {
assert(strcmp(expected_output[i], actual_output[i]) == 0);
}
return 0;
}

0 comments on commit 7c67fa5

Please sign in to comment.