Skip to content

Commit 9690089

Browse files
mprseadbridge
authored andcommitted
Add Transaction class unit test.
1 parent c6810a6 commit 9690089

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2018 ARM Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
#include "mbed.h"
17+
#include "greentea-client/test_env.h"
18+
#include "utest/utest.h"
19+
#include "unity/unity.h"
20+
#include "platform/Transaction.h"
21+
22+
using utest::v1::Case;
23+
24+
static void dummy_callback(int)
25+
{
26+
/* do nothing. */
27+
}
28+
29+
/** Test Transaction class - creation with initialisation
30+
*
31+
* Given is Transaction class.
32+
* When object of the Transaction class is created and initialised.
33+
* Then get_object() returns object's instance for the transaction and get_transaction() returns the transaction.
34+
*
35+
*/
36+
template<typename Type>
37+
void test_Transaction_init()
38+
{
39+
Type object;
40+
const size_t tx_buffer_size = 24;
41+
const size_t rx_buffer_size = 16;
42+
const uint32_t event_id = 123;
43+
const uint8_t word_width = 8;
44+
unsigned char tx_buffer[tx_buffer_size];
45+
unsigned char rx_buffer[rx_buffer_size];
46+
const event_callback_t& callback = dummy_callback;
47+
transaction_t transaction_data =
48+
{ tx_buffer, tx_buffer_size, rx_buffer, rx_buffer_size, event_id, callback, word_width };
49+
50+
Transaction<Type> test_transaction(&object, transaction_data);
51+
52+
TEST_ASSERT_EQUAL(&object, test_transaction.get_object());
53+
54+
TEST_ASSERT_EQUAL((void*)tx_buffer, test_transaction.get_transaction()->tx_buffer);
55+
TEST_ASSERT_EQUAL((void*)rx_buffer, test_transaction.get_transaction()->rx_buffer);
56+
TEST_ASSERT_EQUAL(tx_buffer_size, test_transaction.get_transaction()->tx_length);
57+
TEST_ASSERT_EQUAL(rx_buffer_size, test_transaction.get_transaction()->rx_length);
58+
TEST_ASSERT_EQUAL(event_id, test_transaction.get_transaction()->event);
59+
TEST_ASSERT_EQUAL(word_width, test_transaction.get_transaction()->width);
60+
TEST_ASSERT_EQUAL(callback, test_transaction.get_transaction()->callback);
61+
}
62+
63+
/** Test Transaction class - creation without initialisation
64+
*
65+
* Given is Transaction class.
66+
* When object of the Transaction class is created.
67+
* Then this operation is successful.
68+
*
69+
*/
70+
template<typename Type>
71+
void test_Transaction_empty()
72+
{
73+
Type object;
74+
75+
Transaction<Type> test_transaction;
76+
77+
/* Just indicate successful execution of the test case. */
78+
TEST_ASSERT_TRUE(true);
79+
}
80+
81+
utest::v1::status_t test_setup(const size_t number_of_cases)
82+
{
83+
GREENTEA_SETUP(10, "default_auto");
84+
return utest::v1::verbose_test_setup_handler(number_of_cases);
85+
}
86+
87+
Case cases[] = {
88+
Case("Test Transaction - init <Timer>", test_Transaction_init<Timer>),
89+
Case("Test Transaction - init <Ticker>", test_Transaction_init<Ticker>),
90+
Case("Test Transaction - no init <Timer>", test_Transaction_empty<Timer>),
91+
Case("Test Transaction - no init <Ticker>", test_Transaction_empty<Ticker>),
92+
};
93+
94+
utest::v1::Specification specification(test_setup, cases);
95+
96+
int main()
97+
{
98+
return !utest::v1::Harness::run(specification);
99+
}

0 commit comments

Comments
 (0)