summaryrefslogtreecommitdiffstats
path: root/src/piklab-test/save_load_memory/save_load_memory_check.cpp
blob: e6bb1be36dab0eeb10f6efbde855fe94f6e2af92 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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("")
  TQStringList errors, warnings;
  Device::Memory::WarningTypes wtypes;
  if ( !_memory2->load(_fdest->stream(), errors, wtypes, warnings) ) TEST_FAILED_RETURN(TQString("Error loading hex file into memory %1").tqarg(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)