BA / SerialCom

Fork of OmniWheels by Gustav Atmel

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /* mbed Microcontroller Library
00002  * Copyright (c) 2018 ARM Limited
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 #include "mbed.h"
00017 #include "greentea-client/test_env.h"
00018 #include "utest/utest.h"
00019 #include "unity/unity.h"
00020 #include "platform/Transaction.h"
00021 
00022 using utest::v1::Case;
00023 
00024 static void dummy_callback(int)
00025 {
00026    /* do nothing. */
00027 }
00028 
00029 /** Test Transaction class - creation with initialisation
00030  *
00031  *  Given is Transaction class.
00032  *  When object of the Transaction class is created and initialised.
00033  *  Then get_object() returns object's instance for the transaction and get_transaction() returns the transaction.
00034  *
00035  */
00036 template<typename Type>
00037 void test_Transaction_init()
00038 {
00039     Type object;
00040     const size_t tx_buffer_size = 24;
00041     const size_t rx_buffer_size = 16;
00042     const uint32_t event_id = 123;
00043     const uint8_t word_width = 8;
00044     unsigned char tx_buffer[tx_buffer_size];
00045     unsigned char rx_buffer[rx_buffer_size];
00046     const event_callback_t& callback = dummy_callback;
00047     transaction_t transaction_data =
00048     { tx_buffer, tx_buffer_size, rx_buffer, rx_buffer_size, event_id, callback, word_width };
00049 
00050     Transaction<Type> test_transaction(&object, transaction_data);
00051 
00052     TEST_ASSERT_EQUAL(&object, test_transaction.get_object());
00053 
00054     TEST_ASSERT_EQUAL((void*)tx_buffer, test_transaction.get_transaction()->tx_buffer);
00055     TEST_ASSERT_EQUAL((void*)rx_buffer, test_transaction.get_transaction()->rx_buffer);
00056     TEST_ASSERT_EQUAL(tx_buffer_size,   test_transaction.get_transaction()->tx_length);
00057     TEST_ASSERT_EQUAL(rx_buffer_size,   test_transaction.get_transaction()->rx_length);
00058     TEST_ASSERT_EQUAL(event_id,         test_transaction.get_transaction()->event);
00059     TEST_ASSERT_EQUAL(word_width,       test_transaction.get_transaction()->width);
00060     TEST_ASSERT_EQUAL(callback,         test_transaction.get_transaction()->callback);
00061 }
00062 
00063 /** Test Transaction class - creation without initialisation
00064  *
00065  *  Given is Transaction class.
00066  *  When object of the Transaction class is created.
00067  *  Then this operation is successful.
00068  *
00069  */
00070 template<typename Type>
00071 void test_Transaction_empty()
00072 {
00073     Type object;
00074 
00075     Transaction<Type> test_transaction;
00076 
00077     /* Just indicate successful execution of the test case. */
00078     TEST_ASSERT_TRUE(true);
00079 }
00080 
00081 utest::v1::status_t test_setup(const size_t number_of_cases)
00082 {
00083     GREENTEA_SETUP(10, "default_auto");
00084     return utest::v1::verbose_test_setup_handler(number_of_cases);
00085 }
00086 
00087 Case cases[] = {
00088     Case("Test Transaction - init <Timer>", test_Transaction_init<Timer>),
00089     Case("Test Transaction - init <Ticker>", test_Transaction_init<Ticker>),
00090     Case("Test Transaction - no init <Timer>", test_Transaction_empty<Timer>),
00091     Case("Test Transaction - no init <Ticker>", test_Transaction_empty<Ticker>),
00092 };
00093 
00094 utest::v1::Specification specification(test_setup, cases);
00095 
00096 int main()
00097 {
00098     return !utest::v1::Harness::run(specification);
00099 }