From: Pawel Szewczyk Date: Mon, 28 Sep 2015 11:57:34 +0000 (+0200) Subject: tests: Add basic tests X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ec9dd0684f176a99a469c52af45c856346732425;p=platform%2Fcore%2Fapi%2Fusb-host.git tests: Add basic tests Change-Id: I410c5e796f3e7dfd095c1b877db2dd607714d2d5 Signed-off-by: Pawel Szewczyk --- diff --git a/tests/libhusb-test.c b/tests/libhusb-test.c new file mode 100644 index 0000000..2b3f17c --- /dev/null +++ b/tests/libhusb-test.c @@ -0,0 +1,93 @@ +/* + * libhusb-test.c + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include + +#include "libhusb.h" +#include "libhusb_internal.h" +#include + +/* assertions and checks */ + +/** + * @brief Initialize library context and check results + */ +static int setup_libhusb_context(void **state) +{ + int ret; + libhusb_context *ctx; + libusb_context *lusb_ctx; + + expect_any(libusb_init, ctx); + will_return(libusb_init, lusb_ctx); + will_return(libusb_init, LIBUSB_SUCCESS); + + ret = libhusb_init(&ctx); + + assert_return_code(ret, 0); + assert_ptr_equal(ctx->lusb_ctx, lusb_ctx); + + *state = (void *)ctx; + + return 0; +} + +static int teardown_libhusb_context(void **state) +{ + libhusb_context *ctx; + + ctx = (libhusb_context *)(*state); + expect_any(libusb_exit, ctx); + libhusb_exit(ctx); + + return 0; +} + +/** + * @brief Test if initialization works fine + */ +static void test_init(void **state) +{ + libhusb_context *ctx; + + ctx = (libhusb_context *)(*state); + assert_non_null(ctx); +} + +/* Custom macro for defining test with given name and fixed teardown function */ +#define HUSB_TEST_CTX(func) \ + cmocka_unit_test_setup_teardown(func, setup_libhusb_context, teardown_libhusb_context) + +static struct CMUnitTest tests[] = { + + /** + * @some_test + * TODO: documentation + */ + HUSB_TEST_CTX(test_init), +}; + + +int main(int argc, char **argv) +{ + return cmocka_run_group_tests(tests, NULL, NULL); +}