OLD | NEW |
1 /* Copyright (c) 2009, Google Inc. | 1 /* Copyright (c) 2009, Google Inc. |
2 * All rights reserved. | 2 * All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 */ | 65 */ |
66 #if 0 | 66 #if 0 |
67 void* result[5]; | 67 void* result[5]; |
68 | 68 |
69 if (MallocHook_GetCallerStackTrace(result, sizeof(result)/sizeof(*result), | 69 if (MallocHook_GetCallerStackTrace(result, sizeof(result)/sizeof(*result), |
70 0) < 2) { /* should have this and main */ | 70 0) < 2) { /* should have this and main */ |
71 FAIL("GetCallerStackTrace failed"); | 71 FAIL("GetCallerStackTrace failed"); |
72 } | 72 } |
73 #endif | 73 #endif |
74 | 74 |
75 MallocHook_SetNewHook(&TestNewHook); | 75 if (!MallocHook_AddNewHook(&TestNewHook)) { |
76 MallocHook_SetDeleteHook(&TestDeleteHook); | 76 FAIL("Failed to add new hook"); |
| 77 } |
| 78 if (!MallocHook_AddDeleteHook(&TestDeleteHook)) { |
| 79 FAIL("Failed to add delete hook"); |
| 80 } |
77 free(malloc(10)); | 81 free(malloc(10)); |
78 free(malloc(20)); | 82 free(malloc(20)); |
79 if (g_new_hook_calls != 2) { | 83 if (g_new_hook_calls != 2) { |
80 FAIL("Wrong number of calls to the new hook"); | 84 FAIL("Wrong number of calls to the new hook"); |
81 } | 85 } |
82 if (g_delete_hook_calls != 2) { | 86 if (g_delete_hook_calls != 2) { |
83 FAIL("Wrong number of calls to the delete hook"); | 87 FAIL("Wrong number of calls to the delete hook"); |
84 } | 88 } |
| 89 if (!MallocHook_RemoveNewHook(&TestNewHook)) { |
| 90 FAIL("Failed to remove new hook"); |
| 91 } |
| 92 if (!MallocHook_RemoveDeleteHook(&TestDeleteHook)) { |
| 93 FAIL("Failed to remove delete hook"); |
| 94 } |
85 } | 95 } |
86 | 96 |
87 void TestMallocExtension(void) { | 97 void TestMallocExtension(void) { |
88 int blocks; | 98 int blocks; |
89 size_t total; | 99 size_t total; |
90 int hist[64]; | 100 int hist[64]; |
91 char buffer[200]; | 101 char buffer[200]; |
92 char* x = (char*)malloc(10); | 102 char* x = (char*)malloc(10); |
93 | 103 |
94 MallocExtension_VerifyAllMemory(); | 104 MallocExtension_VerifyAllMemory(); |
(...skipping 25 matching lines...) Expand all Loading... |
120 free(x); | 130 free(x); |
121 } | 131 } |
122 | 132 |
123 int main(int argc, char** argv) { | 133 int main(int argc, char** argv) { |
124 TestMallocHook(); | 134 TestMallocHook(); |
125 TestMallocExtension(); | 135 TestMallocExtension(); |
126 | 136 |
127 printf("PASS\n"); | 137 printf("PASS\n"); |
128 return 0; | 138 return 0; |
129 } | 139 } |
OLD | NEW |