Skip to content

Commit

Permalink
Add pid_od test
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-rabault committed Feb 13, 2023
1 parent 21a17c6 commit 2faca96
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
69 changes: 69 additions & 0 deletions test/tests_od/test_pid/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#include <stdio.h>
#include "unit_test.h"
#include "od_pid.h"

void unittest_Od_pid(void)
{
NEW_TEST_CASE("pid msg conversion test");
{
asserv_pid_t pid;
asserv_pid_t pid_ref = {1, 2, 3};
msg_t msg_ref;
msg_t msg;

NEW_STEP("pid msg conversion FROM test");
msg_ref.header.cmd = PID;
msg_ref.header.size = sizeof(asserv_pid_t);
memcpy(msg_ref.data, &pid_ref, sizeof(asserv_pid_t));
PidOD_PidFromMsg(&pid, &msg_ref);
TEST_ASSERT_EQUAL(pid_ref.p, pid.p);
TEST_ASSERT_EQUAL(pid_ref.i, pid.i);
TEST_ASSERT_EQUAL(pid_ref.d, pid.d);
NEW_STEP("pid msg conversion TO test");
PidOD_PidToMsg(&pid_ref, &msg);
TEST_ASSERT_EQUAL(msg_ref.header.cmd, msg.header.cmd);
TEST_ASSERT_EQUAL(msg_ref.header.size, msg.header.size);
TEST_ASSERT_EQUAL(((asserv_pid_t *)msg_ref.data)->p, ((asserv_pid_t *)msg.data)->p);
TEST_ASSERT_EQUAL(((asserv_pid_t *)msg_ref.data)->i, ((asserv_pid_t *)msg.data)->i);
TEST_ASSERT_EQUAL(((asserv_pid_t *)msg_ref.data)->d, ((asserv_pid_t *)msg.data)->d);
}
NEW_TEST_CASE("pid msg conversion wrong values test");
{
RESET_ASSERT();
asserv_pid_t pid;
msg_t msg;
TRY
{
NEW_STEP("pid msg conversion TO wrong msg_t* value test");
PidOD_PidToMsg(&pid, NULL);
}
TEST_ASSERT_TRUE(IS_ASSERT());
TRY
{
NEW_STEP("pid msg conversion TO wrong asserv_pid_t* value test");
PidOD_PidToMsg(NULL, &msg);
}
TEST_ASSERT_TRUE(IS_ASSERT());
TRY
{
NEW_STEP("pid msg conversion FROM wrong msg_t* value test");
PidOD_PidFromMsg(&pid, NULL);
}
TEST_ASSERT_TRUE(IS_ASSERT());
TRY
{
NEW_STEP("pid msg conversion FROM wrong asserv_pid_t* value test");
PidOD_PidFromMsg(NULL, &msg);
}
TEST_ASSERT_TRUE(IS_ASSERT());
}
}

int main(int argc, char **argv)
{
UNITY_BEGIN();
ASSERT_ACTIVATION(1);
UNIT_TEST_RUN(unittest_Od_pid);

UNITY_END();
}
4 changes: 4 additions & 0 deletions test/tests_od/test_pid/main.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#ifndef MAIN_H
#define MAIN_H

#endif // MAIN_H

0 comments on commit 2faca96

Please sign in to comment.