Home | History | Annotate | Download | only in tests

Lines Matching full:state

173   // Calculate input lengths and fill state.len with them.
191 StringTestState state(SMALL);
192 for (size_t i = 1; i < state.n; i++) {
194 state.NewIteration();
196 memset(state.ptr2, '\2', state.MAX_LEN);
197 state.ptr2[state.MAX_LEN - 1] = '\0';
198 memcpy(state.ptr, state.ptr2, 2 * state.MAX_LEN);
200 memset(state.ptr1, random() & 255, state.len[i]);
201 state.ptr1[random() % state.len[i]] = '\0';
202 state.ptr1[state.len[i] - 1] = '\0';
204 strcpy(state.ptr + state.MAX_LEN - 1, state.ptr1);
206 EXPECT_TRUE(strcat(state.ptr2, state.ptr1) == state.ptr2);
207 EXPECT_TRUE(memcmp(state.ptr, state.ptr2, 2 * state.MAX_LEN) == 0);
215 StringTestState state(SMALL);
216 for (size_t i = 1; i < state.n; i++) {
218 state.NewIteration();
221 memset(state.ptr1, ~seek_char, state.len[i]);
223 memset(state.ptr1, '\1', state.len[i]);
225 state.ptr1[state.len[i] - 1] = '\0';
227 int pos = random() % state.MAX_LEN;
229 if (pos >= state.len[i] - 1) {
231 expected = state.ptr1 + state.len[i] - 1;
236 state.ptr1[pos] = seek_char;
237 expected = state.ptr1 + pos;
240 ASSERT_TRUE(strchr(state.ptr1, seek_char) == expected);
246 StringTestState state(SMALL);
247 for (size_t i = 1; i < state.n; i++) {
249 state.NewIteration();
251 memset(state.ptr1, 'v', state.MAX_LEN);
252 memset(state.ptr2, 'n', state.MAX_LEN);
253 state.ptr1[state.len[i] - 1] = '\0';
254 state.ptr2[state.len[i] - 1] = '\0';
256 int pos = 1 + (random() % (state.MAX_LEN - 1));
259 if (pos >= state.len[i] - 1) {
260 memcpy(state.ptr1, state.ptr2, state.len[i]);
262 actual = strcmp(state.ptr1, state.ptr2);
264 memcpy(state.ptr1, state.ptr2, pos);
265 if (state.ptr1[pos] > state.ptr2[pos]) {
267 } else if (state.ptr1[pos] == state.ptr2[pos]) {
268 state.ptr1[pos + 1] = '\0';
269 state.ptr2[pos + 1] = '\0';
274 actual = strcmp(state.ptr1, state.ptr2);
283 StringTestState state(SMALL);
285 state.NewIteration();
287 size_t pos = random() % state.MAX_LEN;
289 memset(state.ptr1, '\2', pos);
290 state.ptr1[pos] = '\0';
291 state.ptr1[state.MAX_LEN - 1] = '\0';
293 memcpy(state.ptr, state.ptr1, state.MAX_LEN);
295 memset(state.ptr2, '\1', state.MAX_LEN);
296 state.ptr2[state.MAX_LEN - 1] = '\0';
298 memset(state.ptr + state.MAX_LEN, '\1', state.MAX_LEN);
299 memcpy(state.ptr + state.MAX_LEN, state.ptr1, pos + 1);
300 state.ptr[2 * state.MAX_LEN - 1] = '\0';
302 ASSERT_TRUE(strcpy(state.ptr2, state.ptr1) == state.ptr2);
303 ASSERT_FALSE((memcmp(state.ptr1, state.ptr, state.MAX_LEN)) != 0 ||
304 (memcmp(state.ptr2, state.ptr + state.MAX_LEN, state.MAX_LEN) != 0));
344 StringTestState state(SMALL);
345 for (size_t i = 0; i < state.n; i++) {
347 state.NewIteration();
349 memset(state.ptr2, '\2', state.MAX_LEN + state.len[i]);
350 state.ptr2[state.MAX_LEN - 1] = '\0';
351 memcpy(state.ptr, state.ptr2, state.MAX_LEN + state.len[i]);
353 int pos = random() % state.MAX_LEN;
354 memset(state.ptr1, '\3', pos);
355 state.ptr1[pos] = '\0';
356 if (pos < state.len[i]) {
357 memcpy(state.ptr + state.MAX_LEN - 1, state.ptr1, pos + 1);
359 memcpy(state.ptr + state.MAX_LEN - 1, state.ptr1, state.len[i]);
360 state.ptr[state.MAX_LEN + state.len[i] - 1] = '\0';
363 strlcat(state.ptr2, state.ptr1, state.MAX_LEN + state.len[i]);
365 ASSERT_TRUE(memcmp(state.ptr, state.ptr2, state.MAX_LEN + state.len[i]) == 0);
373 StringTestState state(SMALL);
375 state.NewIteration();
381 memset(state.ptr1, rand, state.MAX_LEN);
383 size_t pos = random() % state.MAX_LEN;
384 if (pos < state.MAX_LEN) {
385 state.ptr1[pos] = '\0';
387 memcpy(state.ptr, state.ptr1, state.MAX_LEN);
389 memset(state.ptr2, random() & 255, state.MAX_LEN);
390 memcpy(state.ptr + state.MAX_LEN, state.ptr2, state.MAX_LEN);
392 if (pos > state.MAX_LEN - 1) {
393 memcpy(state.ptr + state.MAX_LEN, state.ptr1, state.MAX_LEN);
394 state.ptr[2 * state.MAX_LEN - 1] = '\0';
396 memcpy(state.ptr + state.MAX_LEN, state.ptr1, pos + 1);
399 ASSERT_EQ(strlcpy(state.ptr2, state.ptr1, state.MAX_LEN), strlen(state.ptr1));
400 ASSERT_FALSE((memcmp(state.ptr1, state.ptr, state.MAX_LEN) != 0) ||
401 (memcmp(state.ptr2, state.ptr + state.MAX_LEN, state.MAX_LEN) != 0));
407 StringTestState state(SMALL);
408 for (size_t i = 1; i < state.n; i++) {
410 state.NewIteration();
412 memset(state.ptr2, '\2', state.MAX_LEN);
413 state.ptr2[state.MAX_LEN - 1] = '\0';
414 memcpy(state.ptr, state.ptr2, 2 * state.MAX_LEN);
416 memset(state.ptr1, random() & 255, state.len[i]);
417 state.ptr1[random() % state.len[i]] = '\0';
418 state.ptr1[state.len[i] - 1] = '\0';
420 size_t pos = strlen(state.ptr1);
422 size_t actual = random() % state.len[i];
423 strncpy(state.ptr + state.MAX_LEN - 1, state.ptr1, std::min(actual, pos));
424 state.ptr[state.MAX_LEN + std::min(actual, pos) - 1] = '\0';
426 ASSERT_TRUE(strncat(state.ptr2, state.ptr1, actual) == state.ptr2);
427 ASSERT_EQ(memcmp(state.ptr, state.ptr2, 2 * state.MAX_LEN), 0);
433 StringTestState state(SMALL);
434 for (size_t i = 1; i < state.n; i++) {
436 state.NewIteration();
438 memset(state.ptr1, 'v', state.MAX_LEN);
439 memset(state.ptr2, 'n', state.MAX_LEN);
440 state.ptr1[state.len[i] - 1] = '\0';
441 state.ptr2[state.len[i] - 1] = '\0';
443 int pos = 1 + (random() % (state.MAX_LEN - 1));
446 if (pos >= state.len[i] - 1) {
447 memcpy(state.ptr1, state.ptr2, state.len[i]);
449 actual = strncmp(state.ptr1, state.ptr2, state.len[i]);
451 memcpy(state.ptr1, state.ptr2, pos);
452 if (state.ptr1[pos] > state.ptr2[pos]) {
454 } else if (state.ptr1[pos] == state.ptr2[pos]) {
455 state.ptr1[pos + 1] = '\0';
456 state.ptr2[pos + 1] = '\0';
461 actual = strncmp(state.ptr1, state.ptr2, state.len[i]);
470 StringTestState state(SMALL);
472 state.NewIteration();
474 memset(state.ptr1, random() & 255, state.MAX_LEN);
475 state.ptr1[random () % state.MAX_LEN] = '\0';
476 memcpy(state.ptr, state.ptr1, state.MAX_LEN);
478 memset(state.ptr2, '\1', state.MAX_LEN);
481 if (memchr(state.ptr1, 0, state.MAX_LEN)) {
482 pos = strlen(state.ptr1);
484 pos = state.MAX_LEN - 1;
487 memset(state.ptr + state.MAX_LEN, '\0', state.MAX_LEN);
488 memcpy(state.ptr + state.MAX_LEN, state.ptr1, pos + 1);
490 ASSERT_TRUE(strncpy(state.ptr2, state.ptr1, state.MAX_LEN) == state.ptr2);
491 ASSERT_FALSE(memcmp(state.ptr1, state.ptr, state.MAX_LEN) != 0 ||
492 memcmp(state.ptr2, state.ptr + state.MAX_LEN, state.MAX_LEN) != 0);
498 StringTestState state(SMALL);
499 for (size_t i = 1; i < state.n; i++) {
501 state.NewIteration();
504 memset(state.ptr1, ~seek_char, state.len[i]);
506 memset(state.ptr1, '\1', state.len[i]);
508 state.ptr1[state.len[i] - 1] = '\0';
510 int pos = random() % state.MAX_LEN;
512 if (pos >= state.len[i] - 1) {
514 expected = state.ptr1 + state.len[i] - 1;
519 state.ptr1[pos] = seek_char;
520 expected = state.ptr1 + pos;
523 ASSERT_TRUE(strrchr(state.ptr1, seek_char) == expected);
530 StringTestState state(SMALL);
531 for (size_t i = 0; i < state.n; i++) {
533 state.NewIteration();
535 memset(state.ptr1, ~seek_char, state.len[i]);
537 int pos = random() % state.MAX_LEN;
539 if (pos >= state.len[i]) {
542 state.ptr1[pos] = seek_char;
543 expected = state.ptr1 + pos;
546 ASSERT_TRUE(memchr(state.ptr1, seek_char, state.len[i]) == expected);
553 StringTestState state(SMALL);
554 for (size_t i = 0; i < state.n; i++) {
556 state.NewIteration();
558 memset(state.ptr1, ~seek_char, state.len[i]);
560 int pos = random() % state.MAX_LEN;
562 if (pos >= state.len[i]) {
565 state.ptr1[pos] = seek_char;
566 state.ptr1 + pos;
569 ASSERT_TRUE(memrchr(state.ptr1, seek_char, state.len[i]) == expected);
575 StringTestState state(SMALL);
576 for (size_t i = 0; i < state.n; i++) {
578 state.NewIteration();
582 memset(state.ptr1, c1, state.MAX_LEN);
583 memset(state.ptr2, c1, state.MAX_LEN);
585 int pos = (state.len[i] == 0) ? 0 : (random() % state.len[i]);
586 state.ptr2[pos] = c2;
589 int actual = memcmp(state.ptr1, state.ptr2, state.MAX_LEN);
597 StringTestState state(LARGE);
599 for (size_t i = 0; i < state.n - 1; i++) {
601 state.NewIteration();
603 size_t pos = random() % (state.MAX_LEN - state.len[i]);
605 memset(state.ptr1, rand, state.len[i]);
606 memset(state.ptr1 + state.len[i], ~rand, state.MAX_LEN - state.len[i]);
608 memset(state.ptr2, rand, state.len[i]);
609 memset(state.ptr2 + state.len[i], ~rand, state.MAX_LEN - state.len[i]);
610 memset(state.ptr2 + pos, '\0', state.len[i]);
612 ASSERT_FALSE(memcpy(state.ptr2 + pos, state.ptr1 + pos, state.len[i]) != state.ptr2 + pos);
613 ASSERT_EQ(0, memcmp(state.ptr1, state.ptr2, state.MAX_LEN));
619 StringTestState state(LARGE);
621 for (size_t i = 0; i < state.n - 1; i++) {
623 state.NewIteration();
625 memset(state.ptr1, ~ch, state.MAX_LEN);
626 memcpy(state.ptr2, state.ptr1, state.MAX_LEN);
628 size_t pos = random () % (state.MAX_LEN - state.len[i]);
629 for (size_t k = pos; k < pos + state.len[i]; k++) {
630 state.ptr1[k] = ch;
633 ASSERT_TRUE(memset(state.ptr2 + pos, ch, state.len[i]) == state.ptr2 + pos);
635 ASSERT_EQ(0, memcmp(state.ptr1, state.ptr2, state.MAX_LEN));
641 StringTestState state(LARGE);
642 for (size_t i = 0; i < state.n - 1; i++) {
644 state.NewIteration();
646 memset(state.ptr1, random() & 255, 2 * state.MAX_LEN);
648 size_t pos = random() % (state.MAX_LEN - state.len[i]);
650 memset(state.ptr1, random() & 255, state.len[i]);
651 memcpy(state.ptr2, state.ptr1, 2 * state.MAX_LEN);
652 memcpy(state.ptr, state.ptr1, state.len[i]);
653 memcpy(state.ptr1 + pos, state.ptr, state.len[i]);
655 ASSERT_TRUE(memmove(state.ptr2 + pos, state.ptr2, state.len[i]) == state.ptr2 + pos);
656 ASSERT_EQ(0, memcmp(state.ptr2, state.ptr1, 2 * state.MAX_LEN));
662 StringTestState state(LARGE);
663 for (size_t i = 0; i < state.n; i++) {
665 state.NewIteration();
667 memset(state.ptr1, random() & 255, state.MAX_LEN);
668 memset(state.ptr1 + state.MAX_LEN, random() & 255, state.MAX_LEN);
669 memcpy(state.ptr2, state.ptr1, 2 * state.MAX_LEN);
671 size_t start = random() % (2 * state.MAX_LEN - state.len[i]);
672 memcpy(state.ptr2 + start, state.ptr1, state.len[i]);
674 bcopy(state.ptr1, state.ptr1 + start, state.len[i]);
675 ASSERT_EQ(0, memcmp(state.ptr1, state.ptr2, 2 * state.MAX_LEN));
681 StringTestState state(LARGE);
683 state.NewIteration();
685 memset(state.ptr1, random() & 255, state.MAX_LEN);
687 size_t start = random() % state.MAX_LEN;
688 size_t end = start + random() % (state.MAX_LEN - start);
690 memcpy(state.ptr2, state.ptr1, start);
691 memset(state.ptr2 + start, '\0', end - start);
692 memcpy(state.ptr2 + end, state.ptr1 + end, state.MAX_LEN - end);
694 bzero(state.ptr1 + start, end - start);
696 ASSERT_EQ(0, memcmp(state.ptr1, state.ptr2, state.MAX_LEN));