diff options
Diffstat (limited to 'src/piklab-test/save_load_memory')
-rw-r--r-- | src/piklab-test/save_load_memory/Makefile.am | 18 | ||||
-rw-r--r-- | src/piklab-test/save_load_memory/save_load_memory_check.cpp | 64 | ||||
-rw-r--r-- | src/piklab-test/save_load_memory/save_load_memory_check.h | 32 |
3 files changed, 114 insertions, 0 deletions
diff --git a/src/piklab-test/save_load_memory/Makefile.am b/src/piklab-test/save_load_memory/Makefile.am new file mode 100644 index 0000000..da9365f --- /dev/null +++ b/src/piklab-test/save_load_memory/Makefile.am @@ -0,0 +1,18 @@ +INCLUDES = -I$(top_srcdir)/src $(all_includes) +METASOURCES = AUTO + +noinst_PROGRAMS = save_load_memory_check +OBJ = $(top_builddir)/src/piklab-test/base/libtest.la \ + $(top_builddir)/src/common/cli/libcli.la \ + $(top_builddir)/src/tools/gputils/libgputils.la \ + $(top_builddir)/src/coff/base/libcoff.la \ + $(top_builddir)/src/common/global/libglobal.la $(top_builddir)/src/devices/list/libdevicelistnoui.la \ + $(top_builddir)/src/devices/pic/pic/libpic.la $(top_builddir)/src/devices/pic/base/libpicbase.la \ + $(top_builddir)/src/devices/pic/xml_data/libpicxml.la \ + $(top_builddir)/src/devices/mem24/mem24/libmem24.la $(top_builddir)/src/devices/mem24/base/libmem24base.la \ + $(top_builddir)/src/devices/mem24/xml_data/libmem24xml.la \ + $(top_builddir)/src/devices/base/libdevicebase.la $(top_builddir)/src/common/common/libcommon.la +save_load_memory_check_DEPENDENCIES = $(OBJ) +save_load_memory_check_LDADD = $(OBJ) $(LIB_KIO) +save_load_memory_check_LDFLAGS = $(all_libraries) $(KDE_RPATH) +save_load_memory_check_SOURCES = save_load_memory_check.cpp diff --git a/src/piklab-test/save_load_memory/save_load_memory_check.cpp b/src/piklab-test/save_load_memory/save_load_memory_check.cpp new file mode 100644 index 0000000..22eb1ea --- /dev/null +++ b/src/piklab-test/save_load_memory/save_load_memory_check.cpp @@ -0,0 +1,64 @@ +/*************************************************************************** + * Copyright (C) 2007 Nicolas Hadacek <hadacek@kde.org> * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ +#include "save_load_memory_check.h" + +#include "devices/base/generic_memory.h" +#include "devices/base/device_group.h" + +//---------------------------------------------------------------------------- +SaveLoadMemoryCheck::SaveLoadMemoryCheck() + : _memory1(0), _memory2(0) +{ + _view = new CLI::View; + PURL::Url dest(PURL::Directory::current(), "test.hex"); + _fdest = new PURL::File(dest, *_view); +} + +SaveLoadMemoryCheck::~SaveLoadMemoryCheck() +{ + _fdest->remove(); + delete _fdest; + delete _view; +} + +bool SaveLoadMemoryCheck::init(const Device::Data &data) +{ + _memory1 = data.group().createMemory(data); + _memory2 = data.group().createMemory(data); + return true; +} + +void SaveLoadMemoryCheck::cleanup(const Device::Data &) +{ + delete _memory1; + _memory1 = 0; + delete _memory2; + _memory2 = 0; +} + +bool SaveLoadMemoryCheck::execute(const Device::Data &data) +{ + // create hex file from blank memory + if ( !_fdest->openForWrite() ) TEST_FAILED_RETURN("") + _memory1->save(_fdest->stream(), HexBuffer::IHX32); + + // read hex file + if ( !_fdest->openForRead() ) TEST_FAILED_RETURN("") + QStringList errors, warnings; + Device::Memory::WarningTypes wtypes; + if ( !_memory2->load(_fdest->stream(), errors, wtypes, warnings) ) TEST_FAILED_RETURN(QString("Error loading hex file into memory %1").arg(data.name())) + + // compare checksums + if ( _memory1->checksum()!=_memory2->checksum() ) TEST_FAILED_RETURN("Memory saved and loaded is different") + TEST_PASSED + return true; +} + +//---------------------------------------------------------------------------- +TEST_MAIN(SaveLoadMemoryCheck) diff --git a/src/piklab-test/save_load_memory/save_load_memory_check.h b/src/piklab-test/save_load_memory/save_load_memory_check.h new file mode 100644 index 0000000..f342560 --- /dev/null +++ b/src/piklab-test/save_load_memory/save_load_memory_check.h @@ -0,0 +1,32 @@ +/*************************************************************************** + * Copyright (C) 2007 Nicolas Hadacek <hadacek@kde.org> * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ +#ifndef SAVE_LOAD_MEMORY_CHECK_H +#define SAVE_LOAD_MEMORY_CHECK_H + +#include "piklab-test/base/device_test.h" +#include "common/cli/cli_log.h" +#include "common/global/pfile.h" +namespace Device { class Memory; } + +class SaveLoadMemoryCheck : public DeviceTest +{ +public: + SaveLoadMemoryCheck(); + virtual ~SaveLoadMemoryCheck(); + virtual bool init(const Device::Data &data); + virtual bool execute(const Device::Data &data); + virtual void cleanup(const Device::Data &data); + +private: + CLI::View *_view; + PURL::File *_fdest; + Device::Memory *_memory1, *_memory2; +}; + +#endif |