added validation code, to walk through a journal_t and make sure it's ok
This commit is contained in:
parent
c3b1de42de
commit
5b0bfeac0c
4 changed files with 106 additions and 0 deletions
23
account.cc
23
account.cc
|
|
@ -89,4 +89,27 @@ std::string account_t::fullname() const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool account_t::valid() const
|
||||||
|
{
|
||||||
|
if (name.find('-') != std::string::npos)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (depth > 16)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
for (transactions_list::const_iterator i = transactions.begin();
|
||||||
|
i != transactions.end();
|
||||||
|
i++)
|
||||||
|
if ((*i)->account != this)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
for (accounts_map::const_iterator i = accounts.begin();
|
||||||
|
i != accounts.end();
|
||||||
|
i++)
|
||||||
|
if (! (*i).second->valid())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace ledger
|
} // namespace ledger
|
||||||
|
|
|
||||||
73
ledger.cc
73
ledger.cc
|
|
@ -8,6 +8,65 @@ namespace ledger {
|
||||||
|
|
||||||
const std::string version = "2.0b";
|
const std::string version = "2.0b";
|
||||||
|
|
||||||
|
bool transaction_t::valid() const
|
||||||
|
{
|
||||||
|
if (! entry)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
bool found = false;
|
||||||
|
for (transactions_list::const_iterator i = entry->transactions.begin();
|
||||||
|
i != entry->transactions.end();
|
||||||
|
i++)
|
||||||
|
if (*i == this) {
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (! found)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (! account)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
found = false;
|
||||||
|
for (transactions_list::const_iterator i = account->transactions.begin();
|
||||||
|
i != account->transactions.end();
|
||||||
|
i++)
|
||||||
|
if (*i == this) {
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (! found)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (! amount.valid())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (cost && ! cost->valid())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (flags & ~0x000f)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool entry_t::valid() const
|
||||||
|
{
|
||||||
|
if (! date || date == -1)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (state != UNCLEARED && state != CLEARED && state != PENDING)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
for (transactions_list::const_iterator i = transactions.begin();
|
||||||
|
i != transactions.end();
|
||||||
|
i++)
|
||||||
|
if ((*i)->entry != this || ! (*i)->valid())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
journal_t::~journal_t()
|
journal_t::~journal_t()
|
||||||
{
|
{
|
||||||
DEBUG_PRINT("ledger.memory.dtors", "dtor journal_t");
|
DEBUG_PRINT("ledger.memory.dtors", "dtor journal_t");
|
||||||
|
|
@ -180,6 +239,20 @@ entry_t * journal_t::derive_entry(strings_list::iterator i,
|
||||||
return added.release();
|
return added.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool journal_t::valid() const
|
||||||
|
{
|
||||||
|
if (! master->valid())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
for (entries_list::const_iterator i = entries.begin();
|
||||||
|
i != entries.end();
|
||||||
|
i++)
|
||||||
|
if (! (*i)->valid())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void initialize_amounts();
|
void initialize_amounts();
|
||||||
void shutdown_amounts();
|
void shutdown_amounts();
|
||||||
|
|
||||||
|
|
|
||||||
8
ledger.h
8
ledger.h
|
|
@ -59,6 +59,8 @@ class transaction_t
|
||||||
if (cost)
|
if (cost)
|
||||||
delete cost;
|
delete cost;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool valid() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -93,6 +95,8 @@ class entry_t
|
||||||
transactions.remove(xact);
|
transactions.remove(xact);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool valid() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -146,6 +150,8 @@ class account_t
|
||||||
bool remove_transaction(transaction_t * xact);
|
bool remove_transaction(transaction_t * xact);
|
||||||
|
|
||||||
friend class journal_t;
|
friend class journal_t;
|
||||||
|
|
||||||
|
bool valid() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline std::ostream& operator<<(std::ostream& out, const account_t& acct) {
|
inline std::ostream& operator<<(std::ostream& out, const account_t& acct) {
|
||||||
|
|
@ -201,6 +207,8 @@ class journal_t
|
||||||
|
|
||||||
entry_t * derive_entry(strings_list::iterator begin,
|
entry_t * derive_entry(strings_list::iterator begin,
|
||||||
strings_list::iterator end) const;
|
strings_list::iterator end) const;
|
||||||
|
|
||||||
|
bool valid() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern const std::string version;
|
extern const std::string version;
|
||||||
|
|
|
||||||
2
main.cc
2
main.cc
|
|
@ -633,6 +633,8 @@ int main(int argc, char * argv[], char * envp[])
|
||||||
TIMER_STOP(write_cache);
|
TIMER_STOP(write_cache);
|
||||||
|
|
||||||
#ifdef DO_CLEANUP
|
#ifdef DO_CLEANUP
|
||||||
|
VALIDATE(journal->valid());
|
||||||
|
|
||||||
shutdown();
|
shutdown();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue