Exercises related to Testing
Write a test program for unique_ptr
Exercice 1
Based on the instructions given in the testing
codelab, add
the following test function to the “test-ptr” test: test that the ownership is
passed correctly between two instances of `std::unique_ptr
Implement the test and verify that it is successful.
Write a test program for raw pointers
Exercice 2
Based on the instructions given in the testing codelab, add the following test function to the “test-ptr” test: test that when creating a raw pointer and deallocating it correctly, the destructor is called as expected.
Implement the test and verify that it is successful.
Write a test program for the Mbed OS Queue
component
In the Multi-tasking using Mbed OS codelab, a number of mechanisms for programming multi-tasking applications have been reviewed. Among those, the Mbed OS queue mechanism was presented with a number of examples.
Exercice 3
Many different test cases can be written for verifying the correctness of the class implementation:
- The function for getting an element from the queue must return
false
if one tries to get an element from an empty queue with a timeout value of0
. This test is implemented in theget_empty_no_timeout()
function. - The function for inserting an element to the queue must succeed when the queue
is not full. It must return false if one tries to insert an element to a full
queue with a given timeout value. In addition, the time spent in the
try_put_for()
method must correspond to the timeout value. This test is implemented in theput_full_timeout()
function. - Testing two scenarios where two separate threads attempt to get and put
elements from a queue with correct behavior: elements cannot be inserted in
the queue when the queue is full and elements cannot be obtained from the
queue when the queue is empty. These two tests are implemented in the
test_get_empty_waitforever()
andtest_put_full_waitforever
functions.
The tests described above must be integrated in a test program under “TESTS/simple-test/basic-queue-test”.