Commit 1be7ba0c by Zoltan Karsa

tesztek: RString, StringPool kezdeti

parent 83104441
......@@ -18,9 +18,11 @@ class StringPool {
// Visszadja, hogy az str objektum szabad, azaz
// kiosztható/megszerezhető-e
bool acquireable(RString& str)
bool acquireable(RString& str);
// Ezután a visszaadott str objektum újra kiosztható másnak
// A függvény "reseteli" a stringet is: a karaktertömb első
// helyére '\0'-t rak.
void release(RString& str);
// Hozzáfűzi str1 végére str2-t.
......@@ -33,7 +35,13 @@ class StringPool {
// érték is szintén kiosztott.
// Ha a paraméterek nem lefoglalt erőforrások,
// akkor eldobja a neptun kódodat!
Rstring& append(RString& str1, const RString& str2);
RString& append(RString& str1, const RString& str2);
// visszadja a pool méretét
size_t size();
// visszadja a szabad objektumok számát
size_t free_size();
};
#endif
\ No newline at end of file
......@@ -21,6 +21,9 @@ class RString {
size_t capacity();
// Visszaadja a string memóriaterületére mutató pointert
operator char*() const;
// Bemásolja a karaktertömbbe a paraméterül kapott
// karakterláncot, ha nem fér bele, eldobja a neptun kódot
RString& operator=(const char* str);
};
#endif
\ No newline at end of file
......@@ -19,14 +19,13 @@
#define ELKESZULT 1
/* ELKESZULT makró:
<= 5: RString tesztjei
<= 3: RString tesztjei
>= 10: Összes teszt
*/
int main() {
GTINIT(std::cin);
#if ELKESZULT > 0
//Caesar titkosítás ellenőrzése
TEST(RString, konstruktorok) {
RString a(100);
EXPECT_STREQ("", a);
......@@ -45,6 +44,99 @@ int main() {
} END
#endif
#if ELKESZULT > 1
TEST(RString, konstruktor kivetel) {
RString a("alma", 5);
EXPECT_STREQ("alma", a);
EXPECT_EQ(5, a.capacity());
EXPECT_EQ(4, a.size());
try {
EXPECT_THROW_THROW(RString b("alma", 4), const char* p);
} catch (const char *p) {
#ifdef CPORTA
EXPECT_ENVCASEEQ("ORG_ID", p);
#endif
}
} END
#endif
#if ELKESZULT > 2
TEST(RString, ertekado_str) {
RString a("alma", 20);
a = "korte";
EXPECT_STREQ("korte", a);
EXPECT_EQ(20, a.capacity());
EXPECT_EQ(5, a.size());
a = "fa";
EXPECT_STREQ("fa", a);
EXPECT_EQ(20, a.capacity());
EXPECT_EQ(2, a.size());
} END
#endif
#if ELKESZULT > 3
TEST(RString, cast) {
RString a("alma", 20);
char* str = a;
strcpy(&str[4], "fa");
EXPECT_STREQ("almafa", a);
EXPECT_EQ(20, a.capacity());
EXPECT_EQ(6, a.size());
} END
#endif
#if ELKESZULT > 4
TEST(StringPool, init) {
StringPool pool(10, 20);
EXPECT_EQ(10, pool.size());
RString& ref = pool.acquire(15);
EXPECT_EQ(20, ref.capacity());
EXPECT_STREQ("", ref);
} END
#endif
#if ELKESZULT > 5
TEST(StringPool, free_size) {
StringPool pool(2, 20);
EXPECT_EQ(2, pool.free_size());
RString& ref1 = pool.acquire(15);
EXPECT_EQ(1, pool.free_size());
RString& ref2 = pool.acquire(20);
EXPECT_EQ(0, pool.free_size());
EXPECT_EQ(20, ref1.capacity());
EXPECT_EQ(20, ref2.capacity());
} END
#endif
#if ELKESZULT > 6
TEST(StringPool, create_new_obj) {
StringPool pool(1, 20);
RString& ref = pool.acquire(15);
EXPECT_EQ(0, pool.free_size());
RString& newobj = pool.acquire(10);
EXPECT_EQ(0, pool.free_size());
EXPECT_EQ(2, pool.size());
EXPECT_EQ(10, newobj.capacity());
} END
#endif
#if ELKESZULT > 7
TEST(StringPool, release) {
StringPool pool(1, 20);
RString& ref = pool.acquire(15);
EXPECT_EQ(1, pool.size());
EXPECT_EQ(0, pool.free_size());
ref = "alma";
pool.release(ref);
EXPECT_EQ(1, pool.free_size());
EXPECT_EQ(1, pool.size());
} END
#endif
if (ELKESZULT < 10)
ADD_FAILURE() << "\nNem futott minden teszteset!" << std::endl;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment