Bug 681238 part 2 - Test WindowsDllInterceptor on functions we intercept in our codebase. r=vlad
authorMike Hommey <mh+mozilla@glandium.org>
Mon, 29 Aug 2011 13:23:45 +0200
changeset 76179 1aed3d7236329d85d28d8d06c60b3e527345b012
parent 76178 be03169f563597cc243a9d8459353598c56acae5
child 76180 f19404f45022ac91b38e1214793a32d9b0dec476
push id3
push userfelipc@gmail.com
push dateFri, 30 Sep 2011 20:09:13 +0000
reviewersvlad
bugs681238
milestone9.0a1
Bug 681238 part 2 - Test WindowsDllInterceptor on functions we intercept in our codebase. r=vlad
toolkit/xre/test/win/TestDllInterceptor.cpp
--- a/toolkit/xre/test/win/TestDllInterceptor.cpp
+++ b/toolkit/xre/test/win/TestDllInterceptor.cpp
@@ -64,16 +64,30 @@ static payload (*orig_rotatePayload)(pay
 
 static payload
 patched_rotatePayload(payload p)
 {
   patched_func_called = true;
   return orig_rotatePayload(p);
 }
 
+bool TestHook(const char *dll, const char *func)
+{
+  void *orig_func;
+  WindowsDllInterceptor TestIntercept;
+  TestIntercept.Init(dll);
+  if (TestIntercept.AddHook(func, 0, &orig_func)) {
+    printf("TEST-PASS | WindowsDllInterceptor | Could hook %s from %s\n", func, dll);
+    return true;
+  } else {
+    printf("TEST-UNEXPECTED-FAIL | WindowsDllInterceptor | Failed to hook %s from %s\n", func, dll);
+    return false;
+  }
+}
+
 int main()
 {
   payload initial = { 0x12345678, 0xfc4e9d31, 0x87654321 };
   payload p0, p1;
   ZeroMemory(&p0, sizeof(p0));
   ZeroMemory(&p1, sizeof(p1));
 
   p0 = rotatePayload(initial);
@@ -119,11 +133,24 @@ int main()
 
   if (p0 == p1) {
     printf("TEST-PASS | WindowsDllInterceptor | Original function worked properly\n");
   } else {
     printf("TEST-UNEXPECTED-FAIL | WindowsDllInterceptor | Original function didn't return the right information\n");
     return 1;
   }
 
-  printf("TEST-PASS | WindowsDllInterceptor | all checks passed\n");
-  return 0;
+  if (TestHook("user32.dll", "GetWindowInfo") &&
+#ifdef _WIN64
+      TestHook("user32.dll", "SetWindowLongPtrA") &&
+      TestHook("user32.dll", "SetWindowLongPtrW") &&
+#else
+      TestHook("user32.dll", "SetWindowLongA") &&
+      TestHook("user32.dll", "SetWindowLongW") &&
+#endif
+      TestHook("user32.dll", "TrackPopupMenu") &&
+      TestHook("ntdll.dll", "LdrLoadDll")) {
+    printf("TEST-PASS | WindowsDllInterceptor | all checks passed\n");
+    return 0;
+  }
+
+  return 1;
 }