Skip to content

Commit c3b33d5

Browse files
committed
Add missing pgmspace test file
1 parent d49024c commit c3b33d5

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

tests/host/core/test_pgmspace.cpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
test_pgmspace.cpp - pgmspace tests
3+
Copyright © 2016 Ivan Grokhotkov
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
*/
15+
16+
#include <catch.hpp>
17+
#include <string.h>
18+
#include <pgmspace.h>
19+
20+
TEST_CASE("strstr_P works as strstr", "[core][pgmspace]")
21+
{
22+
auto t = [](const char* h, const char* n) {
23+
char* strstr_P_result = strstr_P(h, n);
24+
char* strstr_result = strstr(h, n);
25+
REQUIRE(strstr_P_result == strstr_result);
26+
};
27+
28+
// Test case data is from avr-libc, original copyright (c) 2007 Dmitry Xmelkov
29+
// See avr-libc/tests/simulate/pmstring/strstr_P.c
30+
t ("", "");
31+
t("12345", "");
32+
t("ababac", "abac");
33+
t("", "a");
34+
t("b", "a");
35+
t("a", "a");
36+
t("abcbef", "a");
37+
t(".a", "a");
38+
t(".a.", "a");
39+
t("ABCDEFGH", "H");
40+
t("", "12");
41+
t("13", "12");
42+
t("32", "12");
43+
t("12", "12");
44+
t("123", "12");
45+
t("012", "12");
46+
t("01200", "12");
47+
t("a_ab_abc_abcd_abcde", "abcdef");
48+
t("a_ab_abc_abcd_abcde_abcdef", "abcdef");
49+
t("aababcabcdabcde", "abcdef");
50+
t("aababcabcdabcdeabcdef", "abcdef");
51+
t("abaabaaabaaaab", "aaaaab");
52+
t("abaabaaabaaaabaaaaab", "aaaaab");
53+
t("_foo_foo", "foo");
54+
t("A", "a");
55+
}

0 commit comments

Comments
 (0)