Skip to content

Commit

Permalink
Added arduino serial notifier and MariaMole project.
Browse files Browse the repository at this point in the history
  • Loading branch information
BlockoS committed Dec 8, 2012
1 parent cb4989a commit 918d2cc
Show file tree
Hide file tree
Showing 10 changed files with 465 additions and 54 deletions.
97 changes: 97 additions & 0 deletions DataFlash_test.cpp
@@ -0,0 +1,97 @@
#include <SPI.h>
#include "DataFlash.h"

#include "test/Dummy.h"

class DataFlashFixture
{
public:
static const int8_t CHIP_SELECT = 5;
static const int8_t RESET = 6;
static const int8_t WRITE_PROTECT = 7;

public:
void Setup()
{
/* Initialize SPI */
SPI.begin();

/* Let's wait 1 second, allowing use to press the serial monitor button :p */
delay(1000);

/* Initialize dataflash */
m_dataflash.setup(CHIP_SELECT, RESET, WRITE_PROTECT);

delay(10);

/* Read status register */
m_status = m_dataflash.status();

/* Read manufacturer and device ID */
m_dataflash.readID(m_id);
}

void TearDown()
{
/* Disable dataflash */
m_data.disable();
/* And SPI */
SPI.end();
}

protected:
DataFlash m_dataflash;
uint8_t m_status;
DataFlash::ID m_id;
};

class SerialNotifier : public Dummy::CheckFailCallbackInterface
{
public:
SerialNotifier() {}
virtual ~SerialNotifier() {}

virtual void Notify(char const* expected, char const* value, Dummy::Infos const& infos)
{
Serial.print("%s: %s::%s failed at line %d (expected %s, value %s).\n",
infos.Filename(), infos.SuiteName(), infos.TestName(), infos.Line(), expected, value);
}
};


SUITE(SingleDeviceTest)
{
TEST_FIXTURE(InitializationTest, DataFlashFixture)
{
int i;
uint8_t validDensity[10] =
{ 0x0c, 0x14, 0x1c, 0x24, 0x2c, 0x34, 0x3c, 0x10, 0x18, 0x20 };

CHECK(AT45_READY, m_status & AT45_READY);
for(i=0; i<10; i++)
{
CHECK(validDensity[i], m_status & 0x3f);
}
CHECK(0x1f, m_id.manufacture);
}

TEST_FIXTURE(BufferReadWriteTest, DataFlashFixture)
{
// [todo]
}
}

/* Arduino setup hook */
void setup()
{
Serial.begin(115200);
SerialNotifier notifier;

res = Dummy::Runner::Instance().Run(&notifier);
Serial.print("tests run %d\n\ttest failed %d\n\tcheck failed %d\n", res.total, res.failed, res.error);
}

/* Arduino loop */
void loop()
{}

56 changes: 35 additions & 21 deletions test/Callbacks.h
Expand Up @@ -34,6 +34,7 @@
#define CALLBACKS_H

#include "Infos.h"
#include "Result.h"

/**
* @addtogroup DummyUnitTest
Expand All @@ -42,54 +43,67 @@
namespace Dummy
{
/**
* CHECK failure notification interface.
* Test notification interface.
**/
class CheckFailCallbackInterface
class TestNotificationInterface
{
public:
/** Destructor. **/
virtual ~CheckFailCallbackInterface() {};
virtual ~TestNotificationInterface() {};
/**
* Test failure notification.
* @param [in] expected : expected value string.
* @param [in] value : tested value string.
* @param [in] infos : test informations.
**/
virtual void NotifyFailure(char const* expected, char const* value, Infos const& infos) = 0;
/**
* CHECK failure notification.
* @param [in] expected : expected value string.
* @param [in] value : tested value string.
* @param [in] infos : test informations.
**/
virtual void Notify(char const* expected, char const* value, Infos const& infos) = 0;
* Tests result notification.
* @param [in] result : tests result.
**/
virtual void NotifyResult(const Result& result) = 0;
};

/**
* CHECK failure notification helper.
* Test notification helper.
**/
template <class T>
class CheckFailCallback : public CheckFailCallbackInterface
class TestNotification : public TestNotificationInterface
{
public:
typedef void (T::*TNotifyProc) (char const*, char const*, Infos const&);
typedef void (T::*TNotifyFailureProc) (char const*, char const*, Infos const&);
typedef void (T::*TNotifyResultProc) (const Result& result);

/** Constructor. **/
CheckFailCallback(T* handler, TNotifyProc notify);
TestNotification(T* handler, TNotifyFailureProc notifyFailure, TNotifyResultProc notifyResult);
/** Destructor. **/
virtual ~CheckFailCallback() {}
virtual ~TestNotification() {}

/**
* CHECK failure notification.
* Test failure notification.
* @param [in] expected : expected value string.
* @param [in] value : tested value string.
* @param [in] infos : test informations.
**/
virtual void Notify(char const* expected, char const* value, Infos const& infos);
virtual void NotifyFailure(char const* expected, char const* value, Infos const& infos);
/**
* Tests result notification.
* @param [in] result : tests result.
**/
virtual void NotifyResult(const Result& result);

protected:
T* m_handler; /**< Handler instance. **/
TNotifyProc m_notify; /**< Handler method to be called on failure notification. **/
TNotifyFailureProc m_notifyFailure; /**< Handler method to be called on failure notification. **/
TNotifyResultProc m_notifyResult; /**< Handler method to be called on result notification. **/
};

/** Constructor. **/
template <class T>
CheckFailCallback<T>::CheckFailCallback(T* handler, TNotifyProc notify)
TestNotification<T>::TestNotification(T* handler, TNotifyFailureProc notifyFailure, TNotifyResultProc notifyResult)
: m_handler(handler)
, m_notify(notify)
, m_notifyFailure(notifyFailure)
, m_notifyResult(notifyResult)
{}

/**
Expand All @@ -99,9 +113,9 @@ namespace Dummy
* @param [in] infos : test informations.
**/
template <class T>
void CheckFailCallback<T>::Notify(char const* expected, char const* value, Infos const& infos)
void TestNotification<T>::NotifyFailure(char const* expected, char const* value, Infos const& infos)
{
(m_handler->*(m_notify)) (expected, value, infos);
(m_handler->*(m_notifyFailure)) (expected, value, infos);
}
};
/** @} **/
Expand Down
16 changes: 10 additions & 6 deletions test/Runner.cpp
Expand Up @@ -40,7 +40,7 @@ namespace Dummy
{
/** Constructor **/
Runner::Runner()
: m_onCheckFailed(0)
: m_notify(0)
, m_head(0)
, m_tail(0)
{}
Expand Down Expand Up @@ -68,12 +68,12 @@ namespace Dummy

/**
* Process every test declared.
* @param [in] onCheckFailed : CHECK failure notification callback.
* @param [in] notify : Test notification callbacks.
* @return Tests result.
**/
Result Runner::Run(CheckFailCallbackInterface* onCheckFailed)
Result Runner::Run(TestNotificationInterface* notify)
{
m_onCheckFailed = onCheckFailed;
m_notify = notify;
m_result.Reset();
for(Test* it=m_head; it!=0; it=it->m_next, ++m_result.total)
{
Expand All @@ -84,6 +84,10 @@ namespace Dummy
++m_result.failed;
}
}
if(m_notify)
{
m_notify->NotifyResult(m_result);
}
return m_result;
}

Expand All @@ -96,9 +100,9 @@ namespace Dummy
void Runner::OnCheckFailed(char const* expected, char const* value, Infos const& infos)
{
++m_result.error;
if(m_onCheckFailed)
if(m_notify)
{
m_onCheckFailed->Notify(expected, value, infos);
m_notify->NotifyFailure(expected, value, infos);
}
}

Expand Down
6 changes: 3 additions & 3 deletions test/Runner.h
Expand Up @@ -58,10 +58,10 @@ namespace Dummy

/**
* Process every test declared.
* @param [in] onCheckFailed : CHECK failure notification callback (optional).
* @param [in] notify : Notification callback (optional).
* @return Tests result.
**/
Result Run(CheckFailCallbackInterface* onCheckFailed=0);
Result Run(TestNotificationInterface* notify=0);

/**
* CHECK failure notification.
Expand Down Expand Up @@ -91,7 +91,7 @@ namespace Dummy
protected:
Result m_result; /** Test campaign results. **/

CheckFailCallbackInterface* m_onCheckFailed; /** CHECK failure notification callback. **/
TestNotificationInterface* m_notify; /** Test notification callbacks. **/

Test* m_head; /**< First element of the test list. **/
Test* m_tail; /**< Last element of the test list. **/
Expand Down

0 comments on commit 918d2cc

Please sign in to comment.