database: Fix multiple issues
- Check if we are finding the "last" iterator in an empty database - Better print() descriptions - Print test return codes that aren't 0 to help find segfaults Signed-off-by: Anna Schumaker <schumaker.anna@gmail.com>
This commit is contained in:
parent
8ccbad20cc
commit
fc3b5db59e
|
@ -66,14 +66,14 @@ void Database<T> :: clear()
|
|||
template <class T>
|
||||
void Database<T> :: print()
|
||||
{
|
||||
:: print("Database size: %u\n", db.size());
|
||||
:: print("Allocated rows: %u\n", db.size());
|
||||
:: print("Valid rows: %u\n", _size);
|
||||
for (unsigned int i = 0; i < db.size(); i++) {
|
||||
if (db[i].valid == true) {
|
||||
:: print("db[%u] = ", i);
|
||||
db[i].print();
|
||||
:: print("\n");
|
||||
}
|
||||
:: print("\n");
|
||||
}
|
||||
}
|
||||
#endif /* CONFIG_DEBUG */
|
||||
|
@ -126,6 +126,9 @@ unsigned int Database<T> :: first()
|
|||
template <class T>
|
||||
unsigned int Database<T> :: last()
|
||||
{
|
||||
if (_size == 0)
|
||||
return db.size();
|
||||
|
||||
for (unsigned int i = db.size() - 1; i >= 0; i--) {
|
||||
if (db[i].valid == true)
|
||||
return i;
|
||||
|
|
|
@ -9,9 +9,12 @@ GOOD = "%s.good"
|
|||
def run_test(target, source, env):
|
||||
res = str(target[0])
|
||||
out = open(res, 'w')
|
||||
ret = subprocess.call("%s" % source[0], stdout = out)
|
||||
ret = subprocess.call("%s" % source[0], stdout = out, stderr = out)
|
||||
out.close()
|
||||
|
||||
if ret != 0:
|
||||
print "Test returns: ", ret
|
||||
|
||||
if (len(source) == 2) and (ret == 0):
|
||||
good = str(source[1])
|
||||
if (subprocess.call("diff -u %s %s" % (good, res), shell = True) != 0):
|
||||
|
|
|
@ -157,9 +157,27 @@ void test_6()
|
|||
Database<DBTest> db("", DB_NORMAL);
|
||||
for (unsigned int i = 0; i < 10; i++)
|
||||
db.insert(DBTest(i));
|
||||
db.print();
|
||||
print_db(db);
|
||||
db.clear();
|
||||
db.print();
|
||||
print_db(db);
|
||||
}
|
||||
|
||||
/*
|
||||
* Print databases with no valid rows
|
||||
*/
|
||||
void test_7()
|
||||
{
|
||||
print("\nTest 7\n");
|
||||
Database<DBTest> db("", DB_NORMAL);
|
||||
print_db(db);
|
||||
|
||||
for (unsigned int i = 0; i < 10; i++)
|
||||
db.insert(DBTest(i));
|
||||
print_db(db);
|
||||
|
||||
for (unsigned int i = 0; i < 10; i++)
|
||||
db.remove(i);
|
||||
print_db(db);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
|
@ -171,6 +189,7 @@ int main(int argc, char **argv)
|
|||
test_4();
|
||||
test_5();
|
||||
test_6();
|
||||
test_7();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -300040,7 +300040,7 @@ db[3] = 3
|
|||
db[4] = 4
|
||||
|
||||
Test 5
|
||||
Database size: 10
|
||||
Allocated rows: 10
|
||||
Valid rows: 10
|
||||
db[0] = 0
|
||||
db[1] = 1
|
||||
|
@ -300055,7 +300055,9 @@ db[9] = 9
|
|||
|
||||
Test 6
|
||||
Database size: 10
|
||||
Valid rows: 10
|
||||
Num rows: 10
|
||||
First: 0
|
||||
Last: 9
|
||||
db[0] = 0
|
||||
db[1] = 1
|
||||
db[2] = 2
|
||||
|
@ -300067,4 +300069,30 @@ db[7] = 7
|
|||
db[8] = 8
|
||||
db[9] = 9
|
||||
Database size: 0
|
||||
Valid rows: 0
|
||||
Num rows: 0
|
||||
First: 0
|
||||
Last: 0
|
||||
|
||||
Test 7
|
||||
Database size: 0
|
||||
Num rows: 0
|
||||
First: 0
|
||||
Last: 0
|
||||
Database size: 10
|
||||
Num rows: 10
|
||||
First: 0
|
||||
Last: 9
|
||||
db[0] = 0
|
||||
db[1] = 1
|
||||
db[2] = 2
|
||||
db[3] = 3
|
||||
db[4] = 4
|
||||
db[5] = 5
|
||||
db[6] = 6
|
||||
db[7] = 7
|
||||
db[8] = 8
|
||||
db[9] = 9
|
||||
Database size: 0
|
||||
Num rows: 10
|
||||
First: 10
|
||||
Last: 10
|
||||
|
|
Loading…
Reference in New Issue