2102
test_skip_block (void)
2106
size_t pos, lineno, endpos;
2109
TEST_FUNCTION ("nih_config_skip_block");
2110
program_name = "test";
2113
/* Check that we can find the end of a simple block. pos should be
2114
* updated to point past the block, and the returned endpos should
2115
* point at the end of the block itself.
2117
TEST_FEATURE ("with simple block");
2118
strcpy (buf, "this is\na test\nend foo\nblah\n");
2121
ret = nih_config_skip_block (buf, strlen (buf), &pos, NULL,
2126
TEST_EQ (endpos, 15);
2129
/* Check that the line number is incremented for each line that we
2130
* discover in the block, including the terminating line.
2132
TEST_FEATURE ("with line number set");
2136
ret = nih_config_skip_block (buf, strlen (buf), &pos, &lineno,
2141
TEST_EQ (endpos, 15);
2142
TEST_EQ (lineno, 5);
2145
/* Check that we can find the end of a block that ends in a terminator
2146
* with extraneous whitespace around the words.
2148
TEST_FEATURE ("with whitespace in terminator");
2149
strcpy (buf, "this is\na test\n end \t foo \nblah\n");
2152
ret = nih_config_skip_block (buf, strlen (buf), &pos, NULL,
2157
TEST_EQ (endpos, 15);
2160
/* Check that we can find the end of a block that ends in a
2161
* terminator which is at the end of the file.
2163
TEST_FEATURE ("with terminator at end of file");
2164
strcpy (buf, "this is\na test\nend foo");
2167
ret = nih_config_skip_block (buf, strlen (buf), &pos, NULL,
2172
TEST_EQ (endpos, 15);
2175
/* Check that we can find the end of a block that ends in a
2176
* terminator which has a comment following it.
2178
TEST_FEATURE ("with terminator and comment");
2179
strcpy (buf, "this is\na test\nend foo # comment\ntest\n");
2182
ret = nih_config_skip_block (buf, strlen (buf), &pos, NULL,
2187
TEST_EQ (endpos, 15);
2190
/* Check that we can find the end of a block that ends in a
2191
* terminator which has a comment and then the end of file.
2193
TEST_FEATURE ("with terminator and comment at end of file");
2194
strcpy (buf, "this is\na test\nend foo # comment");
2197
ret = nih_config_skip_block (buf, strlen (buf), &pos, NULL,
2202
TEST_EQ (endpos, 15);
2205
/* Check that various bogus forms of terminator are ignored.
2207
TEST_FEATURE ("with various things that aren't terminators");
2208
strcpy (buf, "endfoo\nend a\nend fooish\nend foo\ntest\n");
2211
ret = nih_config_skip_block (buf, strlen (buf), &pos, NULL,
2216
TEST_EQ (endpos, 24);
2219
/* Check that reaching the end of the file without finding the block
2220
* terminator causes an error to be raised and NULL to be returned.
2222
TEST_FEATURE ("with no terminator before end of file");
2223
strcpy (buf, "this is\na test\n");
2227
ret = nih_config_skip_block (buf, strlen (buf), &pos, &lineno,
2232
TEST_EQ (lineno, 4);
2234
err = nih_error_get ();
2235
TEST_EQ (err->number, NIH_CONFIG_UNTERMINATED_BLOCK);
2068
2240
static int handler_called = 0;
2069
2241
static void *last_data = NULL;