aboutsummaryrefslogtreecommitdiff
path: root/src/main/test_extractor.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/test_extractor.c')
-rw-r--r--src/main/test_extractor.c113
1 files changed, 61 insertions, 52 deletions
diff --git a/src/main/test_extractor.c b/src/main/test_extractor.c
index f1d3b85..13aa1c8 100644
--- a/src/main/test_extractor.c
+++ b/src/main/test_extractor.c
@@ -20,6 +20,11 @@
20/** 20/**
21 * @file main/test_extractor.c 21 * @file main/test_extractor.c
22 * @brief plugin for testing GNU libextractor 22 * @brief plugin for testing GNU libextractor
23 * Data file (or buffer) for this test must be 150 * 1024 bytes long,
24 * first 4 bytes must be "test", all other bytes should be equal to
25 * <FILE_OFFSET> % 256. The test client must return 0 after seeing
26 * "Hello World!" metadata, and return 1 after seeing "Goodbye!"
27 * metadata.
23 * @author Christian Grothoff 28 * @author Christian Grothoff
24 */ 29 */
25#include "platform.h" 30#include "platform.h"
@@ -44,93 +49,97 @@ EXTRACTOR_test_extract_method (struct EXTRACTOR_ExtractContext *ec)
44{ 49{
45 unsigned char *dp; 50 unsigned char *dp;
46 51
47 if ( (NULL == ec->config) || 52 if ((NULL == ec->config) || (0 != strcmp (ec->config, "test")))
48 (0 != strcmp (ec->config, "test")) )
49 return; /* only run in test mode */ 53 return; /* only run in test mode */
50 if ( (4 != ec->read (ec->cls, 54 if (4 != ec->read (ec->cls, &dp, 4))
51 &dp,
52 4)) ||
53 (0 != strncmp ("test",
54 (const char*) dp,
55 4) ) )
56 { 55 {
57 fprintf (stderr, "Reading at offset 0 failed\n"); 56 fprintf (stderr, "Reading at offset 0 failed\n");
58 abort (); 57 abort ();
59 } 58 }
60 if (1024 * 150 != 59 if (0 != strncmp ("test", (const char*) dp, 4))
61 ec->get_size (ec->cls)) 60 {
61 fprintf (stderr, "Unexpected data at offset 0\n");
62 abort ();
63 }
64 if (1024 * 150 != ec->get_size (ec->cls))
62 { 65 {
63 fprintf (stderr, "Unexpected file size returned (expected 150k)\n"); 66 fprintf (stderr, "Unexpected file size returned (expected 150k)\n");
64 abort (); 67 abort ();
65 } 68 }
66 if (1024 * 100 != 69
67 ec->seek (ec->cls, 70 if (1024 * 100 + 4 != ec->seek (ec->cls, 1024 * 100 + 4, SEEK_SET))
68 1024 * 100 + 4,
69 SEEK_SET))
70 { 71 {
71 fprintf (stderr, "Failure to seek (SEEK_SET)\n"); 72 fprintf (stderr, "Failure to seek (SEEK_SET)\n");
72 abort (); 73 abort ();
73 } 74 }
74 if ( (1 != ec->read (ec->cls, 75 if (1 != ec->read (ec->cls, &dp, 1))
75 &dp,
76 1)) ||
77 ((1024 * 100 + 4) % 256 != *dp) )
78 { 76 {
79 fprintf (stderr, "Failure to read at 100k + 4\n"); 77 fprintf (stderr, "Failure to read at 100k + 4\n");
80 abort (); 78 abort ();
81 } 79 }
82 if (1024 * 50 - 3 != 80 if ((1024 * 100 + 4) % 256 != *dp)
83 ec->seek (ec->cls, 81 {
84 - (1024 * 50 + 7), 82 fprintf (stderr, "Unexpected data at offset 100k + 4\n");
85 SEEK_CUR)) 83 abort ();
84 }
85
86 if (((1024 * 100 + 4) + 1 - (1024 * 50 + 7)) !=
87 ec->seek (ec->cls, - (1024 * 50 + 7), SEEK_CUR))
86 { 88 {
87 fprintf (stderr, "Failure to seek (SEEK_SET)\n"); 89 fprintf (stderr, "Failure to seek (SEEK_SET)\n");
88 abort (); 90 abort ();
89 } 91 }
90 if ( (1 != ec->read (ec->cls, 92 if (1 != ec->read (ec->cls, &dp, 1))
91 &dp,
92 1)) ||
93 ((1024 * 50 - 3) % 256 != *dp) )
94 { 93 {
95 fprintf (stderr, "Failure to read at 50k - 3\n"); 94 fprintf (stderr, "Failure to read at 50k - 3\n");
96 abort (); 95 abort ();
97 } 96 }
98 if (1024 * 150 - 3 != 97 if (((1024 * 100 + 4) + 1 - (1024 * 50 + 7)) % 256 != *dp)
99 ec->seek (ec->cls,
100 - 2,
101 SEEK_END))
102 { 98 {
103 fprintf (stderr, "Failure to seek (SEEK_SET)\n"); 99 fprintf (stderr, "Unexpected data at offset 50k - 3\n");
100 abort ();
101 }
102
103 if (1024 * 150 != ec->seek (ec->cls, 0, SEEK_END))
104 {
105 fprintf (stderr, "Failure to seek (SEEK_END)\n");
106 abort ();
107 }
108 if (0 != ec->read (ec->cls, &dp, 1))
109 {
110 fprintf (stderr, "Failed to receive EOF at 150k\n");
111 abort ();
112 }
113
114 if (1024 * 150 - 2 != ec->seek (ec->cls, -2, SEEK_END))
115 {
116 fprintf (stderr, "Failure to seek (SEEK_END - 2)\n");
117 abort ();
118 }
119 if (1 != ec->read (ec->cls, &dp, 1))
120 {
121 fprintf (stderr, "Failure to read at 150k - 3\n");
104 abort (); 122 abort ();
105 } 123 }
106 if ( (1 != ec->read (ec->cls, 124 if ((1024 * 150 - 2) % 256 != *dp)
107 &dp,
108 1)) ||
109 ((1024 * 150 - 2) % 256 != *dp) )
110 { 125 {
111 fprintf (stderr, "Failure to read at 150k - 2\n"); 126 fprintf (stderr, "Unexpected data at offset 150k - 3\n");
112 abort (); 127 abort ();
113 } 128 }
114 if (0 != 129
115 ec->proc (ec->cls, 130 if (0 != ec->proc (ec->cls, "test", EXTRACTOR_METATYPE_COMMENT,
116 "test", 131 EXTRACTOR_METAFORMAT_UTF8, "<no mime>", "Hello world!",
117 EXTRACTOR_METATYPE_COMMENT, 132 strlen ("Hello world!") + 1))
118 EXTRACTOR_METAFORMAT_UTF8,
119 "<no mime>",
120 "Hello world!",
121 strlen ("Hello world!") + 1))
122 { 133 {
123 fprintf (stderr, "Unexpected return value from 'proc'\n"); 134 fprintf (stderr, "Unexpected return value from 'proc'\n");
124 abort (); 135 abort ();
125 } 136 }
126 if (1 != 137 /* The test assumes that client orders us to stop extraction
127 ec->proc (ec->cls, 138 * after seeing "Goodbye!".
128 "test", 139 */
129 EXTRACTOR_METATYPE_COMMENT, 140 if (1 != ec->proc (ec->cls, "test", EXTRACTOR_METATYPE_COMMENT,
130 EXTRACTOR_METAFORMAT_UTF8, 141 EXTRACTOR_METAFORMAT_UTF8, "<no mime>", "Goodbye!",
131 "<no mime>", 142 strlen ("Goodbye!") + 1))
132 "Goodbye!",
133 strlen ("Goodbye!") + 1))
134 { 143 {
135 fprintf (stderr, "Unexpected return value from 'proc'\n"); 144 fprintf (stderr, "Unexpected return value from 'proc'\n");
136 abort (); 145 abort ();