summaryrefslogtreecommitdiff
path: root/maximus/phy/src/PhySciMsgTest.cpp
blob: 2292a06f5b0ed245c37607e9ef9f9f5a8d19f179 (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
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "PhySciMsgTest.h"

#include "PhySciMsg.h"
#include "PhyProcessor.h"
#include "SciServer.h"

#include "Logger.h"
#include "Error.h"

#include <iostream>
using namespace std;

CPPUNIT_TEST_SUITE_REGISTRATION (PhySciMsgTest);


void PhySciMsgTest::setUp (void)
{
  logTest();
  
  mpSciServer = new SciServer();
  mpPhyProcessor = new PhyProcessor (mpSciServer);
  mpPhySciMsg = new PhySciMsg (mpPhyProcessor);
}


void PhySciMsgTest::tearDown (void) 
{
  logTest();
  
  if (NULL != mpPhySciMsg)
  {
    delete (mpPhySciMsg);
    mpPhySciMsg = NULL;
  }
  if (NULL != mpPhyProcessor)
  {
  	delete (mpPhyProcessor);
    mpPhyProcessor = NULL;
  }
  if (NULL != mpSciServer)
  {
    delete (mpSciServer);
    mpSciServer = NULL;
  }
}


void PhySciMsgTest::dispatchMsgTest (void)
{
  logTest();

  if (NULL != mpPhySciMsg)
  {
    int type = PHY_TYPE_TONEMASK;
    unsigned int carrierNb = (PHY_CARRIER_NB+7)/8; 
    unsigned char tonemask[sizeof(unsigned int) + carrierNb];
    memcpy(tonemask, &carrierNb, sizeof(unsigned int));
    memset(tonemask + sizeof(unsigned int), 'T', carrierNb);
    mpPhySciMsg->setSpecializedSciMsgDataLength(sizeof(unsigned int) + (PHY_CARRIER_NB+7)/8);
    mpPhySciMsg->setSpecializedSciMsgData(tonemask);
    CPPUNIT_ASSERT_MESSAGE("setSpecializedSciMsgType failed", mpPhySciMsg->setSpecializedSciMsgType((Phy_Type)type));
    CPPUNIT_ASSERT_MESSAGE("dispatchMsg failed", mpPhySciMsg->dispatchMsg());

    type = PHY_TYPE_RX;
    Sci_Msg_Station_Id txStationId = 123;
    mpPhySciMsg->setSpecializedSciMsgDataLength(sizeof(Sci_Msg_Station_Id));
    mpPhySciMsg->setSpecializedSciMsgData((unsigned char *)&txStationId);
    CPPUNIT_ASSERT_MESSAGE("setSpecializedSciMsgType failed", mpPhySciMsg->setSpecializedSciMsgType((Phy_Type)type));
    CPPUNIT_ASSERT_MESSAGE("dispatchMsg failed", mpPhySciMsg->dispatchMsg());
  }
  else
  {
    CPPUNIT_FAIL ("PhySciMsg pointer is NULL");
  }
}