Skip to content
This repository has been archived by the owner on May 22, 2024. It is now read-only.

Commit

Permalink
test: add find_form
Browse files Browse the repository at this point in the history
  • Loading branch information
jyhi committed Dec 13, 2023
1 parent a92980b commit e9c6ad7
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions test/thing/test_find_form/test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
SPDX-FileCopyrightText: 2023 Junde Yhi <junde@yhi.moe>
SPDX-License-Identifier: MIT
*/

/*!
\file
\brief Unit tests for `tinywot_thing_find_form()`.
*/

#include <stddef.h>
#include <string.h>
#include <tinywot/core.h>
#include <tinywot-test.h>
#include <unity.h>

static void tinywot_thing_find_form_should_succeed(void) {
enum tinywot_status status = TINYWOT_STATUS_ERROR_GENERIC;
struct tinywot_thing *thing = tinywot_test_tinywot_thing_new_example();
struct tinywot_form *form = NULL;

status = tinywot_thing_find_form(
thing, &form, "/status", TINYWOT_OPERATION_TYPE_READPROPERTY
);

TEST_ASSERT_EQUAL(TINYWOT_STATUS_SUCCESS, status);
TEST_ASSERT_NOT_NULL(form);

tinywot_test_tinywot_thing_delete(thing);
}

static void tinywot_thing_find_form_should_fail_when_not_found(void) {
enum tinywot_status status = TINYWOT_STATUS_ERROR_GENERIC;
struct tinywot_thing *thing = tinywot_test_tinywot_thing_new_example();
struct tinywot_form *form = NULL;

status = tinywot_thing_find_form(
thing, &form, "/lorem", TINYWOT_OPERATION_TYPE_INVOKEACTION
);

TEST_ASSERT_EQUAL(TINYWOT_STATUS_ERROR_NOT_FOUND, status);
TEST_ASSERT_NULL(form);

tinywot_test_tinywot_thing_delete(thing);
}

void setUp(void) {}
void tearDown(void) {}

int main(void) {
UNITY_BEGIN();

RUN_TEST(tinywot_thing_find_form_should_succeed);
RUN_TEST(tinywot_thing_find_form_should_fail_when_not_found);

return UNITY_END();
}

0 comments on commit e9c6ad7

Please sign in to comment.