void CUnitTest::AddTest(const char* name, TestFn function) { TRACE(TRACE_ENABLE); if (m_testStatus == eTS_UNINITIALISED) { m_tests.push_back(STest(name, function)); } }
but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include <scope/test.h> #include <algorithm> #include <cstring> #include "stest.h" SCOPE_FIXTURE_CTOR(abSearch, STest, STest("ab")) { const byte* text = (const byte*)"abc"; fixture.search(text, text + 3, 0); SCOPE_ASSERT_EQUAL(1u, fixture.Hits.size()); SCOPE_ASSERT_EQUAL(SearchHit(0, 2, 0), fixture.Hits[0]); } SCOPE_FIXTURE_CTOR(aOrbSearch, STest, STest("a|b")) { const byte* text = (const byte*)"abc"; fixture.search(text, text + 3, 0); SCOPE_ASSERT_EQUAL(2u, fixture.Hits.size()); SCOPE_ASSERT_EQUAL(SearchHit(0, 1, 0), fixture.Hits[0]); SCOPE_ASSERT_EQUAL(SearchHit(1, 2, 0), fixture.Hits[1]); } SCOPE_FIXTURE_CTOR(aOrbOrcSearch, STest, STest("a|b|c")) {
void STests(int level) { // unit self tests char *a, *b, *c; int i,j,k; int ol = S_DEBUG_LEVEL; S_DEBUG_LEVEL=level; // test a = SCreate("Hello World"); STest(a,"Hello World","string creation"); // test SFree(a); STestI((intptr_t)a,0,"string free and set to NULL"); // test a = SCreate("0123456789"); i = SPos(a,"0"); STestI(i,0,"position of char on the begining of string"); i = SPos(a,"012"); STestI(i,0,"position of string on the begining of string"); i = SPos(a,"9"); STestI(i,9,"position of char on the end of string"); i = SPos(a,"789"); STestI(i,7,"position of string on the end of string"); i = SPos(a,"4"); STestI(i,4,"position of char in the middle of string"); i = SPos(a,"456"); STestI(i,4,"position of string in the middle of string"); SFree(a); // test //S_DEBUG_LEVEL=1; a = SCreate("I walked into bar and talked to bar"); b = SCreateReplace(a,"bar","BAR"); STest(b,"I walked into BAR and talked to BAR", "replacing on the end of string"); SFree(a); SFree(b); // test a = SCreate("foo bar foo"); b = SCreateReplace(a,"bar","BAR"); STest(b,"foo BAR foo", "replacing in the middle of string once"); SFree(a); SFree(b); // test a = SCreate("foo bar and bar foo"); b = SCreateReplace(a,"bar","BAR"); STest(b,"foo BAR and BAR foo", "replacing in the middle of string twice"); SFree(a); SFree(b); // test a = SCreate("foo bar foo"); b = SCreateReplace(a,"foo","FOO"); STest(b,"FOO bar FOO", "replacing on the begining and end of string"); SFree(a); SFree(b); // test a = SCreate("abc"); b = SCreateReplace(a,"b","B"); STest(b,"aBc", "replacing one char on 2nd position"); SFree(a); SFree(b); // test a = SCreate("abc"); b = SCreateReplace(a,"a","A"); STest(b,"Abc", "replacing one char on 1st position"); SFree(a); SFree(b); // test a = SCreate("abc"); b = SCreateReplace(a,"c","C"); STest(b,"abC", "replacing one char on last position"); SFree(a); SFree(b); // test a = SCreate("abc"); b = SCreateReplace(a,"b","BBB"); STest(b,"aBBBc", "replacing one char with 3char string"); SFree(a); SFree(b); // test a = SCreate("abbbc"); b = SCreateReplace(a,"bbb","B"); STest(b,"aBc", "replacing string with one char"); SFree(a); SFree(b); // test a = SCreate("abbba"); b = SCreateReplace(a,"a","AA"); STest(b,"AAbbbAA", "multiple replacement with different length"); SFree(a); SFree(b); // test a = SCreate("97%"); b = SCreateReplace(a,"%",""); STest(b,"97", "replacing percent sing from 97%%"); SFree(a); SFree(b); // test a = SCreate(" Mono: Playback 62 [97%] [-2.00dB] [on]"); i = SPos(a,"["); j = SPos(a,"]"); b = SCreateBetween(a,i+1,j-1); c = SCreateReplace(b,"%",""); k = SInt(c); STestI(k,97,"extracting alsa volume"); SFree(a); SFree(b); SFree(c); // test 012345678901234 a = SCreate("AbcdeAbcdeAbcde"); b = SCreateBetween(a,10,50); STest(b,"Abcde","create string between longer that source"); SFree(a); SFree(b); // test 012345678901234 a = SCreate("AbcdeAbcdeAbcde"); i = SPosFrom(a,"A",0); STestI(i,0,"position from 0 at 0"); SFree(a); // test 012345678901234 a = SCreate("AbcdeAbcdeAbcde"); i = SPosFrom(a,"A",1); STestI(i,5,"position from 1 at 5"); SFree(a); // test 012345678901234 a = SCreate("AbcdeAbcdeAbcde"); i = SPosFrom(a,"A",8); STestI(i,10,"position from 8 at 10"); SFree(a); // test 012345678901234 a = SCreate("AbcdeAbcdeAbcde"); i = SPosFrom(a,"A",11); STestI(i,-1,"position from 11 at -1"); SFree(a); // test 012345678901234 a = SCreate("AbcdeAbcdeAbcde"); i = SPosFrom(a,"e",11); STestI(i,14,"position from 14 at -1"); SFree(a); if (S_DEBUG_LEVEL >= 1) printf("STest: all %d tests passed\n",S_TEST_ID); S_DEBUG_LEVEL=ol; }