Last change
on this file since 3eb5f993 was
8be729f,
checked in by Andrew Beach <ajbeach@…>, 4 years ago
|
That should fix the memory module. Simply removed all the special features.
|
-
Property mode set to
100644
|
File size:
1.3 KB
|
Rev | Line | |
---|
[aabb846] | 1 | // Testing the smart pointers (counter_ptr and unique_ptr). |
---|
| 2 | |
---|
| 3 | #include <memory.hfa> |
---|
[8be729f] | 4 | #include <assert.h> |
---|
[aabb846] | 5 | |
---|
| 6 | void counter_test(void) { |
---|
| 7 | counter_ptr(int) ptr0 = 3; |
---|
| 8 | |
---|
| 9 | { |
---|
| 10 | counter_ptr(int) ptr1 = ptr0; |
---|
| 11 | *ptr1 = -7; |
---|
| 12 | } |
---|
| 13 | assert(-7 == *ptr0); |
---|
| 14 | |
---|
| 15 | { |
---|
| 16 | counter_ptr(int) ptr2 = 4; |
---|
| 17 | ptr0 = ptr2; |
---|
| 18 | } |
---|
| 19 | assert(4 == *ptr0); |
---|
| 20 | |
---|
| 21 | { |
---|
| 22 | counter_ptr(int) ptr3 = ptr0; |
---|
| 23 | counter_ptr(int) ptr4 = ptr0; |
---|
| 24 | } |
---|
| 25 | } |
---|
| 26 | |
---|
| 27 | void unique_test(void) { |
---|
| 28 | unique_ptr(char) ptr_a = 'a'; |
---|
| 29 | unique_ptr(char) ptr_b = 'b'; |
---|
| 30 | move(ptr_a, ptr_b); |
---|
| 31 | assert(ptr_b == 0); |
---|
| 32 | assert(*ptr_a == 'b'); |
---|
| 33 | |
---|
| 34 | unique_ptr(char) ptr_c = 'c'; |
---|
| 35 | ptr_c = 0; |
---|
| 36 | } |
---|
| 37 | |
---|
| 38 | void pointer_equality(void) { |
---|
| 39 | { |
---|
| 40 | counter_ptr(int) null = 0p; |
---|
| 41 | assert(null == 0); |
---|
| 42 | counter_ptr(int) hold = -7; |
---|
| 43 | assert(hold != 0); |
---|
| 44 | counter_ptr(int) twin = hold; |
---|
| 45 | assert(hold == twin); |
---|
| 46 | } |
---|
| 47 | { |
---|
| 48 | unique_ptr(int) null = 0p; |
---|
| 49 | assert(null == 0); |
---|
| 50 | unique_ptr(int) hold = -7; |
---|
| 51 | assert(hold != 0); |
---|
| 52 | } |
---|
| 53 | } |
---|
| 54 | |
---|
[8be729f] | 55 | void declare_test(void) { |
---|
| 56 | counter_ptr(int) ptr_i0 = 3; |
---|
| 57 | counter_ptr(char) ptr_c0 = 'a'; |
---|
| 58 | counter_ptr(float) ptr_f0 = 3.5f; |
---|
| 59 | counter_ptr(double) ptr_d0 = 3.5; |
---|
| 60 | |
---|
| 61 | unique_ptr(int) ptr_i1 = 3; |
---|
| 62 | unique_ptr(char) ptr_c1 = 'a'; |
---|
| 63 | unique_ptr(float) ptr_f1 = 3.5f; |
---|
| 64 | unique_ptr(double) ptr_d1 = 3.5; |
---|
| 65 | } |
---|
| 66 | |
---|
[aabb846] | 67 | int main(int argc, char * argv[]) { |
---|
| 68 | counter_test(); |
---|
| 69 | unique_test(); |
---|
| 70 | pointer_equality(); |
---|
[8be729f] | 71 | |
---|
| 72 | printf("done\n"); |
---|
[aabb846] | 73 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.