00001
00002
00003 #include <config.h>
00004 #include <cppunit/extensions/HelperMacros.h>
00005 #include <cppunit/Asserter.h>
00006 #include "Asserts.h"
00007 #include "CSIS3600.h"
00008 #ifdef HAVE_STD_NAMESPACE
00009 using namespace std;
00010 #endif
00011
00012 class sis3600tests : public CppUnit::TestFixture {
00013 CPPUNIT_TEST_SUITE(sis3600tests);
00014 CPPUNIT_TEST(Construction);
00015 CPPUNIT_TEST(LED);
00016 CPPUNIT_TEST(LatchMode);
00017 CPPUNIT_TEST(ExternalClear);
00018 CPPUNIT_TEST(FClearWindow);
00019 CPPUNIT_TEST(LatchTest);
00020 CPPUNIT_TEST(FIFOClear);
00021 CPPUNIT_TEST(Read1);
00022 CPPUNIT_TEST(Read);
00023 CPPUNIT_TEST_SUITE_END();
00024
00025
00026 private:
00027 CSIS3600* m_pModule;
00028 public:
00029 void setUp() {
00030 m_pModule = new CSIS3600(0x38383800);
00031 }
00032 void tearDown() {
00033 delete m_pModule;
00034 }
00035 protected:
00036 void Construction();
00037 void LED();
00038 void LatchMode();
00039 void ExternalClear();
00040 void FClearWindow();
00041 void LatchTest();
00042 void Read1();
00043 void Read();
00044 void FIFOClear();
00045
00046 private:
00047 void LatchEvent();
00048 };
00049
00050 CPPUNIT_TEST_SUITE_REGISTRATION(sis3600tests);
00051
00052
00053
00054
00055
00056 void sis3600tests::Construction()
00057 {
00058
00059
00060 try {
00061 CSIS3600 module(0x38383800);
00062 }
00063 catch (...) {
00064 FAIL("Exception on construction of valid module!!");
00065 }
00066
00067
00068
00069 bool failed = true;
00070 try {
00071 CSIS3600 module(0x10000000);
00072 }
00073 catch (string msg) {
00074 failed = false;
00075 }
00076 catch (...) {
00077 FAIL("Bad construction threw wrong type of exception.");
00078 }
00079 if(failed) {
00080 FAIL("Construction of bad moudule did not throw an exception");
00081 }
00082
00083
00084 }
00085
00086
00087
00088
00089
00090 void
00091 sis3600tests::LED()
00092 {
00093 m_pModule->LightLed();
00094 ASSERT(m_pModule->isLedLit());
00095
00096
00097 m_pModule->ClearLed();
00098 ASSERT(!m_pModule->isLedLit());
00099 }
00100
00101
00102
00103
00104 void
00105 sis3600tests::LatchMode()
00106 {
00107 m_pModule->SetLatchMode();
00108 ASSERT(m_pModule->isLatchMode());
00109
00110 m_pModule->SetCoincidenceMode();
00111 ASSERT(!m_pModule->isLatchMode());
00112 }
00113
00114
00115
00116 void
00117 sis3600tests::ExternalClear()
00118 {
00119 m_pModule->EnableExternalClear();
00120 ASSERT(m_pModule->ExternalClearEnabled());
00121
00122 m_pModule->DisableExternalClear();
00123 ASSERT(!m_pModule->ExternalClearEnabled());
00124
00125 }
00126
00127
00128
00129 void
00130 sis3600tests::FClearWindow()
00131 {
00132
00133
00134
00135
00136
00137
00138 int i;
00139 for(i = 220; i <= 25720; i+=100 ) {
00140 try {
00141 m_pModule->SetFastClearWindow(i);
00142 EQ(i, m_pModule->GetFastClearWindow());
00143 }
00144 catch (string msg) {
00145 FAIL("Valid fast clear window set -> Exception");
00146 }
00147 }
00148
00149
00150
00151
00152 bool failed;
00153 try {
00154 failed = true;
00155 m_pModule->SetFastClearWindow(169);
00156 }
00157 catch (string msg) {
00158 failed = false;
00159 }
00160 catch (...) {
00161 FAIL("Invalid fast clear window threw wrong exception type");
00162 }
00163 if(failed) {
00164 FAIL("Invalid fast clear window set succeeded !!!");
00165 }
00166
00167 try {
00168 failed = true;
00169 m_pModule->SetFastClearWindow(25771);
00170
00171 }
00172 catch(string msg) {
00173 failed = false;
00174 }
00175 catch(...) {
00176 FAIL("Invalid fast clear window set threw wrong exception type");
00177 }
00178 if(failed) {
00179 FAIL("Invalid fast clear window set succeeded!!");
00180 }
00181
00182
00183 m_pModule->Reset();
00184 EQ(220, m_pModule->GetFastClearWindow());
00185
00186 }
00187
00188
00189 void sis3600tests::LatchEvent()
00190 {
00191 m_pModule->StartLatch();
00192 m_pModule->EndLatch();
00193 m_pModule->Clock();
00194 }
00195
00196
00197
00198 void
00199 sis3600tests::LatchTest()
00200 {
00201 ASSERT(!(m_pModule->DataReady()));
00202
00203 m_pModule->SetCoincidenceMode();
00204 m_pModule->Enable();
00205 LatchEvent();
00206
00207 ASSERT(m_pModule->DataReady());
00208 }
00209
00210
00211
00212
00213
00214 void
00215 sis3600tests::FIFOClear()
00216 {
00217 LatchTest();
00218
00219 m_pModule->ClearData();
00220
00221 ASSERT(!(m_pModule->DataReady()));
00222 }
00223
00224
00225
00226
00227
00228
00229 void
00230 sis3600tests::Read1()
00231 {
00232
00233
00234 m_pModule->Reset();
00235 m_pModule->SetCoincidenceMode();
00236 m_pModule->Enable();
00237
00238 for(int i =0; i < 2; i++) {
00239 LatchEvent();
00240 }
00241
00242 unsigned long data;
00243 try {
00244 ASSERT(m_pModule->DataReady());
00245
00246 data = m_pModule->Read();
00247
00248 ASSERT(m_pModule->DataReady());
00249
00250 data = m_pModule->Read();
00251 ASSERT(!m_pModule->DataReady());
00252 }
00253 catch (string msg) {
00254 FAIL("Read threw exception even with data!");
00255 }
00256
00257
00258
00259 bool failed = true;
00260 try {
00261 data = m_pModule->Read();
00262 }
00263 catch (string msg) {
00264 failed = false;
00265 }
00266 catch (...) {
00267 FAIL("Empty read threw wrong exception type");
00268 }
00269 if(failed) {
00270 FAIL("Empty read did not throw an exception");
00271 }
00272
00273
00274 }
00275
00276
00277
00278 void
00279 sis3600tests::Read()
00280 {
00281 m_pModule->Reset();
00282 m_pModule->SetCoincidenceMode();
00283 m_pModule->Enable();
00284
00285
00286
00287 for(int i = 0; i < 100; i ++) {
00288 LatchEvent();
00289 }
00290 unsigned long data[30];
00291 unsigned int nread;
00292
00293 nread = m_pModule->Read(data, 30);
00294 EQMSG("First 30", 30U, nread);
00295
00296 nread = m_pModule->Read(data, 30);
00297 EQMSG("Second 30", 30U, nread);
00298
00299 nread = m_pModule->Read(data, 30);
00300 EQMSG("Last full 30", 30U, nread);
00301
00302 nread = m_pModule->Read(data, 30);
00303 EQMSG("Partial read", 10U, nread);
00304 }