Mercurial > trustbridge
annotate common/selftest.c @ 1080:898b1ddcca11
help-de: new introduction; switched faq to tech-ref and added arbeitsweise.
author | Bernhard Reiter <bernhard@intevation.de> |
---|---|
date | Thu, 11 Sep 2014 12:00:10 +0200 |
parents | fa3f4e2370d3 |
children | edbf5e5e88f4 |
rev | line source |
---|---|
634
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1 #include "selftest.h" |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
2 #include "binverify.h" |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
3 #include "strhelp.h" |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
4 #include "logging.h" |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
5 |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
6 bool |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
7 selftest() |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
8 { |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
9 #ifdef WIN32 |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
10 wchar_t wPath[MAX_PATH]; |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
11 char *utf8path = NULL; |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
12 |
904
f89b41fa7048
Fix whitespace errors
Andre Heinecke <andre.heinecke@intevation.de>
parents:
634
diff
changeset
|
13 if (!GetModuleFileNameW (NULL, wPath, MAX_PATH - 1)) |
634
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
14 { |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
15 PRINTLASTERROR ("Failed to obtain module file name. Path too long?"); |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
16 return false; |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
17 } |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
18 |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
19 /* wPath might not be 0 terminated */ |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
20 wPath[MAX_PATH - 1] = '\0'; |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
21 |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
22 utf8path = wchar_to_utf8 (wPath, wcsnlen(wPath, MAX_PATH)); |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
23 |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
24 if (utf8path == NULL) |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
25 { |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
26 ERRORPRINTF ("Failed to convert module path to utf-8"); |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
27 return false; |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
28 } |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
29 |
1073
fa3f4e2370d3
Fix selftest it was broken during the move out of verify_binary
Andre Heinecke <andre.heinecke@intevation.de>
parents:
904
diff
changeset
|
30 if (verify_binary (utf8path, strlen(utf8path)) != VerifyValid) |
634
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
31 { |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
32 ERRORPRINTF ("Verification of the binary failed"); |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
33 syslog_error_printf ("Integrity check failed."); |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
34 xfree(utf8path); |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
35 return false; |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
36 } |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
37 |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
38 xfree(utf8path); |
1073
fa3f4e2370d3
Fix selftest it was broken during the move out of verify_binary
Andre Heinecke <andre.heinecke@intevation.de>
parents:
904
diff
changeset
|
39 return true; |
634
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
40 #else |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
41 if (!verify_binary ("/proc/self/exe", 14) != VerifyValid) |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
42 { |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
43 syslog_error_printf ("Integrity check failed."); |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
44 return false; |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
45 } |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
46 #endif |
80d1a80b3e8d
Factor out selftest for better test and reviewability
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
47 } |