gtest_labjack_node.cpp
Go to the documentation of this file.
00001 
00024 #include "gtest/gtest.h"
00025 #include "ljacklm_mock.h"
00026 #include "labjack_node.h"
00027 #include "labjack_data.h"
00028 
00029 using testing::_;
00030 using testing::DoAll;
00031 using testing::SetArgumentPointee;
00032 using testing::AnyNumber;
00033 using testing::Return;
00034 
00035 // Test getStateDs()
00036 TEST(LabjackNode, GetStateDs)
00037 {
00038     MockLjacklmWrapper mock;
00039 
00040     EXPECT_CALL(mock, config())
00041         .Times(1)
00042         .WillOnce(Return(0));
00043     EXPECT_CALL(mock, readDIOs(_, _))
00044         .Times(1)
00045         .WillOnce(Return(0));
00046     EXPECT_CALL(mock, readAIs(_, _, _))
00047         .Times(2)
00048         .WillRepeatedly(Return(0));
00049     EXPECT_CALL(mock, readDirectionDs(_))
00050         .Times(1)
00051         .WillOnce(Return(0));
00052 
00053     LabjackNode labjack_node(&mock);
00054 
00055     // success
00056     EXPECT_CALL(mock, readDIOs(_, _))
00057         .Times(1)
00058         .WillOnce(Return(0));
00059 
00060     ASSERT_FLOAT_EQ(0, labjack_node.getStateDs());
00061 
00062     // fail
00063     EXPECT_CALL(mock, readDIOs(_, _))
00064         .Times(1)
00065         .WillOnce(Return(-1));
00066 
00067     ASSERT_EQ(-1, labjack_node.getStateDs());
00068 }
00069 
00070 // Test setStateDs()
00071 TEST(LabjackNode, SetStateDs)
00072 {
00073     MockLjacklmWrapper mock;
00074 
00075     EXPECT_CALL(mock, config())
00076         .Times(1)
00077         .WillOnce(Return(0));
00078     EXPECT_CALL(mock, readDIOs(_, _))
00079         .Times(1)
00080         .WillOnce(Return(0));
00081     EXPECT_CALL(mock, readAIs(_, _, _))
00082         .Times(2)
00083         .WillRepeatedly(Return(0));
00084     EXPECT_CALL(mock, readDirectionDs(_))
00085         .Times(1)
00086         .WillOnce(Return(0));
00087 
00088     LabjackNode labjack_node(&mock);
00089 
00090     // success
00091     EXPECT_CALL(mock, writeDIOsCONFIG(_, _))
00092         .Times(1)
00093         .WillOnce(Return(0));
00094 
00095     ASSERT_EQ(0, labjack_node.setStateDs(0));
00096 
00097     // fail
00098     EXPECT_CALL(mock, writeDIOsCONFIG(_, _))
00099         .Times(1)
00100         .WillOnce(Return(-1));
00101 
00102     ASSERT_EQ(-1, labjack_node.setStateDs(0));
00103 }
00104 
00105 // Test getStateD()
00106 TEST(LabjackNode, GetStateD)
00107 {
00108     MockLjacklmWrapper mock;
00109 
00110     EXPECT_CALL(mock, config())
00111         .Times(1)
00112         .WillOnce(Return(0));
00113     EXPECT_CALL(mock, readDIOs(_, _))
00114         .Times(1)
00115         .WillOnce(Return(0));
00116     EXPECT_CALL(mock, readAIs(_, _, _))
00117         .Times(2)
00118         .WillRepeatedly(Return(0));
00119     EXPECT_CALL(mock, readDirectionDs(_))
00120         .Times(1)
00121         .WillOnce(Return(0));
00122 
00123     LabjackNode labjack_node(&mock);
00124 
00125     // success
00126     EXPECT_CALL(mock, readDIOs(_, _))
00127         .Times(1)
00128         .WillOnce(Return(0));
00129 
00130     ASSERT_EQ(0, labjack_node.getStateD(0));
00131 
00132     // fail
00133     EXPECT_CALL(mock, readDIOs(_, _))
00134         .Times(1)
00135         .WillOnce(Return(-1));
00136 
00137     ASSERT_EQ(1, labjack_node.getStateD(0));
00138 
00139     ASSERT_EQ(-1, labjack_node.getStateD(-1));
00140 }
00141 
00142 // Test setStateD()
00143 TEST(LabjackNode, SetStateD)
00144 {
00145     MockLjacklmWrapper mock;
00146 
00147     EXPECT_CALL(mock, config())
00148         .Times(1)
00149         .WillOnce(Return(0));
00150     EXPECT_CALL(mock, readDIOs(_, _))
00151         .Times(1)
00152         .WillOnce(Return(0));
00153     EXPECT_CALL(mock, readAIs(_, _, _))
00154         .Times(2)
00155         .WillRepeatedly(Return(0));
00156     EXPECT_CALL(mock, readDirectionDs(_))
00157         .Times(1)
00158         .WillOnce(Return(0));
00159 
00160     LabjackNode labjack_node(&mock);
00161 
00162     // success
00163     EXPECT_CALL(mock, writeDCONFIG(_, 1))
00164         .Times(1)
00165         .WillOnce(Return(0));
00166 
00167     ASSERT_EQ(0, labjack_node.setStateD(0));
00168 
00169     // fail
00170     EXPECT_CALL(mock, writeDCONFIG(_, 1))
00171         .Times(1)
00172         .WillOnce(Return(-1));
00173 
00174     ASSERT_EQ(-1, labjack_node.setStateD(0));
00175 }
00176 
00177 // Test clearStateD()
00178 TEST(LabjackNode, ClearStateD)
00179 {
00180     MockLjacklmWrapper mock;
00181 
00182     EXPECT_CALL(mock, config())
00183         .Times(1)
00184         .WillOnce(Return(0));
00185     EXPECT_CALL(mock, readDIOs(_, _))
00186         .Times(1)
00187         .WillOnce(Return(0));
00188     EXPECT_CALL(mock, readAIs(_, _, _))
00189         .Times(2)
00190         .WillRepeatedly(Return(0));
00191     EXPECT_CALL(mock, readDirectionDs(_))
00192         .Times(1)
00193         .WillOnce(Return(0));
00194 
00195     LabjackNode labjack_node(&mock);
00196 
00197     // success
00198     EXPECT_CALL(mock, writeDCONFIG(_, 0))
00199         .Times(1)
00200         .WillOnce(Return(0));
00201 
00202     ASSERT_EQ(0, labjack_node.clearStateD(0));
00203 
00204     // fail
00205     EXPECT_CALL(mock, writeDCONFIG(_, 0))
00206         .Times(1)
00207         .WillOnce(Return(-1));
00208 
00209     ASSERT_EQ(-1, labjack_node.clearStateD(0));
00210 }
00211 
00212 // Test getDsDirection()
00213 TEST(LabjackNode, GetDsDirection)
00214 {
00215     MockLjacklmWrapper mock;
00216 
00217     EXPECT_CALL(mock, config())
00218         .Times(1)
00219         .WillOnce(Return(0));
00220     EXPECT_CALL(mock, readDIOs(_, _))
00221         .Times(1)
00222         .WillOnce(Return(0));
00223     EXPECT_CALL(mock, readAIs(_, _, _))
00224         .Times(2)
00225         .WillRepeatedly(Return(0));
00226     EXPECT_CALL(mock, readDirectionDs(_))
00227         .Times(1)
00228         .WillOnce(Return(0));
00229 
00230     LabjackNode labjack_node(&mock);
00231 
00232     // success
00233     EXPECT_CALL(mock, readDirectionDs(_))
00234         .Times(1)
00235         .WillOnce(Return(0));
00236 
00237     ASSERT_EQ(0, labjack_node.getDsDirection());
00238 
00239     // fail
00240     EXPECT_CALL(mock, readDirectionDs(_))
00241         .Times(1)
00242         .WillOnce(Return(-1));
00243 
00244     ASSERT_EQ(-1, labjack_node.getDsDirection());
00245 }
00246 
00247 // Test getStateIOs()
00248 TEST(LabjackNode, GetStateIOs)
00249 {
00250     MockLjacklmWrapper mock;
00251 
00252     EXPECT_CALL(mock, config())
00253         .Times(1)
00254         .WillOnce(Return(0));
00255     EXPECT_CALL(mock, readDIOs(_, _))
00256         .Times(1)
00257         .WillOnce(Return(0));
00258     EXPECT_CALL(mock, readAIs(_, _, _))
00259         .Times(2)
00260         .WillRepeatedly(Return(0));
00261     EXPECT_CALL(mock, readDirectionDs(_))
00262         .Times(1)
00263         .WillOnce(Return(0));
00264 
00265     LabjackNode labjack_node(&mock);
00266 
00267     // success
00268     EXPECT_CALL(mock, readDIOs(_, _))
00269         .Times(1)
00270         .WillOnce(Return(0));
00271 
00272     ASSERT_EQ(0, labjack_node.getStateIOs());
00273 
00274     // fail
00275     EXPECT_CALL(mock, readDIOs(_, _))
00276         .Times(1)
00277         .WillOnce(Return(-1));
00278 
00279     ASSERT_EQ(-1, labjack_node.getStateIOs());
00280 }
00281 
00282 // Test getDsDirection()
00283 TEST(LabjackNode, SetStateIOs)
00284 {
00285     MockLjacklmWrapper mock;
00286 
00287     EXPECT_CALL(mock, config())
00288         .Times(1)
00289         .WillOnce(Return(0));
00290     EXPECT_CALL(mock, readDIOs(_, _))
00291         .Times(1)
00292         .WillOnce(Return(0));
00293     EXPECT_CALL(mock, readAIs(_, _, _))
00294         .Times(2)
00295         .WillRepeatedly(Return(0));
00296     EXPECT_CALL(mock, readDirectionDs(_))
00297         .Times(1)
00298         .WillOnce(Return(0));
00299 
00300     LabjackNode labjack_node(&mock);
00301 
00302     // success
00303     EXPECT_CALL(mock, writeDIOsCONFIG(_, _))
00304         .Times(1)
00305         .WillOnce(Return(0));
00306 
00307     ASSERT_EQ(0, labjack_node.setStateIOs(0));
00308 
00309     // fail
00310     EXPECT_CALL(mock, writeDIOsCONFIG(_, _))
00311         .Times(1)
00312         .WillOnce(Return(-1));
00313 
00314     ASSERT_EQ(-1, labjack_node.setStateIOs(0));
00315 }
00316 
00317 // Test getStateIO()
00318 TEST(LabjackNode, GetStateIO)
00319 {
00320     MockLjacklmWrapper mock;
00321 
00322     EXPECT_CALL(mock, config())
00323         .Times(1)
00324         .WillOnce(Return(0));
00325     EXPECT_CALL(mock, readDIOs(_, _))
00326         .Times(1)
00327         .WillOnce(Return(0));
00328     EXPECT_CALL(mock, readAIs(_, _, _))
00329         .Times(2)
00330         .WillRepeatedly(Return(0));
00331     EXPECT_CALL(mock, readDirectionDs(_))
00332         .Times(1)
00333         .WillOnce(Return(0));
00334 
00335     LabjackNode labjack_node(&mock);
00336 
00337     // success
00338     EXPECT_CALL(mock, readDIOs(_, _))
00339         .Times(1)
00340         .WillOnce(Return(0));
00341 
00342     ASSERT_EQ(0, labjack_node.getStateIO(0));
00343 
00344     // fail
00345     EXPECT_CALL(mock, readDIOs(_, _))
00346         .Times(1)
00347         .WillOnce(Return(-1));
00348 
00349     ASSERT_EQ(1, labjack_node.getStateIO(0));
00350 
00351     ASSERT_EQ(-1, labjack_node.getStateIO(-1));
00352     ASSERT_EQ(-1, labjack_node.getStateIO(NUM_LIN_IO + 1));
00353 }
00354 
00355 // Test setStateIO()
00356 TEST(LabjackNode, SetStateIO)
00357 {
00358     MockLjacklmWrapper mock;
00359 
00360     EXPECT_CALL(mock, config())
00361         .Times(1)
00362         .WillOnce(Return(0));
00363     EXPECT_CALL(mock, readDIOs(_, _))
00364         .Times(1)
00365         .WillOnce(Return(0));
00366     EXPECT_CALL(mock, readAIs(_, _, _))
00367         .Times(2)
00368         .WillRepeatedly(Return(0));
00369     EXPECT_CALL(mock, readDirectionDs(_))
00370         .Times(1)
00371         .WillOnce(Return(0));
00372 
00373     LabjackNode labjack_node(&mock);
00374 
00375     // success
00376     EXPECT_CALL(mock, writeIO(_, 1))
00377         .Times(1)
00378         .WillOnce(Return(0));
00379 
00380     ASSERT_EQ(0, labjack_node.setStateIO(0));
00381 
00382     // fail
00383     EXPECT_CALL(mock, writeIO(_, 1))
00384         .Times(1)
00385         .WillOnce(Return(-1));
00386 
00387     ASSERT_EQ(-1, labjack_node.setStateIO(0));
00388 }
00389 
00390 // Test clearStateIO()
00391 TEST(LabjackNode, ClearStateIO)
00392 {
00393     MockLjacklmWrapper mock;
00394 
00395     EXPECT_CALL(mock, config())
00396         .Times(1)
00397         .WillOnce(Return(0));
00398     EXPECT_CALL(mock, readDIOs(_, _))
00399         .Times(1)
00400         .WillOnce(Return(0));
00401     EXPECT_CALL(mock, readAIs(_, _, _))
00402         .Times(2)
00403         .WillRepeatedly(Return(0));
00404     EXPECT_CALL(mock, readDirectionDs(_))
00405         .Times(1)
00406         .WillOnce(Return(0));
00407 
00408     LabjackNode labjack_node(&mock);
00409 
00410     // success
00411     EXPECT_CALL(mock, writeIO(_, 0))
00412         .Times(1)
00413         .WillOnce(Return(0));
00414 
00415     ASSERT_EQ(0, labjack_node.clearStateIO(0));
00416 
00417     // fail
00418     EXPECT_CALL(mock, writeIO(_, 0))
00419         .Times(1)
00420         .WillOnce(Return(-1));
00421 
00422     ASSERT_EQ(-1, labjack_node.clearStateIO(0));
00423 }
00424 
00425 // Test getAIs()
00426 TEST(LabjackNode, GetAI)
00427 {
00428     MockLjacklmWrapper mock;
00429 
00430     EXPECT_CALL(mock, config())
00431         .Times(1)
00432         .WillOnce(Return(0));
00433     EXPECT_CALL(mock, readDIOs(_, _))
00434         .Times(1)
00435         .WillOnce(Return(0));
00436     EXPECT_CALL(mock, readAIs(_, _, _))
00437         .Times(2)
00438         .WillRepeatedly(Return(0));
00439     EXPECT_CALL(mock, readDirectionDs(_))
00440         .Times(1)
00441         .WillOnce(Return(0));
00442 
00443     LabjackNode labjack_node(&mock);
00444 
00445     // success
00446     EXPECT_CALL(mock, readAI(_, _))
00447         .Times(1)
00448         .WillOnce(Return(0));
00449 
00450     ASSERT_EQ(0.0, labjack_node.getAI(0));
00451 
00452     // fail
00453     EXPECT_CALL(mock, readAI(_, _))
00454         .Times(1)
00455         .WillOnce(Return(-1));
00456 
00457     ASSERT_FLOAT_EQ(-1, labjack_node.getAI(0));
00458 
00459     ASSERT_FLOAT_EQ(-1, labjack_node.getAI(-1));
00460     ASSERT_FLOAT_EQ(-1, labjack_node.getAI(NUM_LIN_AI + 1));
00461 }
00462 
00463 // Test setAOs()
00464 TEST(LabjackNode, SetAOs)
00465 {
00466     MockLjacklmWrapper mock;
00467 
00468     EXPECT_CALL(mock, config())
00469         .Times(1)
00470         .WillOnce(Return(0));
00471     EXPECT_CALL(mock, readDIOs(_, _))
00472         .Times(1)
00473         .WillOnce(Return(0));
00474     EXPECT_CALL(mock, readAIs(_, _, _))
00475         .Times(2)
00476         .WillRepeatedly(Return(0));
00477     EXPECT_CALL(mock, readDirectionDs(_))
00478         .Times(1)
00479         .WillOnce(Return(0));
00480 
00481     LabjackNode labjack_node(&mock);
00482 
00483     float2 data;
00484 
00485     // success
00486     EXPECT_CALL(mock, writeAOs(_, _))
00487         .Times(1)
00488         .WillOnce(Return(0));
00489 
00490     ASSERT_EQ(0, labjack_node.setAOs(data));
00491 
00492     // fail
00493     EXPECT_CALL(mock, writeAOs(_, _))
00494         .Times(1)
00495         .WillOnce(Return(-1));
00496 
00497     ASSERT_EQ(-1, labjack_node.setAOs(data));
00498 }
00499 
00500 // Test setPulseD()
00501 TEST(LabjackNode, SetPulseD)
00502 {
00503     MockLjacklmWrapper mock;
00504 
00505     EXPECT_CALL(mock, config())
00506         .Times(1)
00507         .WillOnce(Return(0));
00508     EXPECT_CALL(mock, readDIOs(_, _))
00509         .Times(1)
00510         .WillOnce(Return(0));
00511     EXPECT_CALL(mock, readAIs(_, _, _))
00512         .Times(2)
00513         .WillRepeatedly(Return(0));
00514     EXPECT_CALL(mock, readDirectionDs(_))
00515         .Times(1)
00516         .WillOnce(Return(0));
00517 
00518     LabjackNode labjack_node(&mock);
00519 
00520     t_pulseData data;
00521 
00522     // fail
00523     EXPECT_CALL(mock, readDirectionDs(_))
00524         .Times(1)
00525         .WillOnce(Return(0));
00526 
00527     ASSERT_EQ(-1, labjack_node.setPulseD(data));
00528 
00529     EXPECT_CALL(mock, readDirectionDs(_))
00530         .Times(1)
00531         .WillOnce(Return(-1));
00532 
00533     ASSERT_EQ(-1, labjack_node.setPulseD(data));
00534 }
00535 
00536 // Test setPulseIO()
00537 TEST(LabjackNode, SetPulseIO)
00538 {
00539     MockLjacklmWrapper mock;
00540 
00541     EXPECT_CALL(mock, config())
00542         .Times(1)
00543         .WillOnce(Return(0));
00544     EXPECT_CALL(mock, readDIOs(_, _))
00545         .Times(1)
00546         .WillOnce(Return(0));
00547     EXPECT_CALL(mock, readAIs(_, _, _))
00548         .Times(2)
00549         .WillRepeatedly(Return(0));
00550     EXPECT_CALL(mock, readDirectionDs(_))
00551         .Times(1)
00552         .WillOnce(Return(0));
00553 
00554     LabjackNode labjack_node(&mock);
00555 
00556     t_pulseData data;
00557 
00558     // fail
00559     EXPECT_CALL(mock, readDirectionDs(_))
00560         .Times(1)
00561         .WillOnce(Return(0));
00562 
00563     ASSERT_EQ(-1, labjack_node.setPulseIO(data));
00564 
00565     EXPECT_CALL(mock, readDirectionDs(_))
00566         .Times(1)
00567         .WillOnce(Return(-1));
00568 
00569     ASSERT_EQ(-1, labjack_node.setPulseIO(data));
00570 }
00571 
00572 // Test setState()
00573 TEST(LabjackNode, SetState)
00574 {
00575     MockLjacklmWrapper mock;
00576 
00577     EXPECT_CALL(mock, config())
00578         .Times(1)
00579         .WillOnce(Return(0));
00580     EXPECT_CALL(mock, readDIOs(_, _))
00581         .Times(1)
00582         .WillOnce(Return(0));
00583     EXPECT_CALL(mock, readAIs(_, _, _))
00584         .Times(2)
00585         .WillRepeatedly(Return(0));
00586     EXPECT_CALL(mock, readDirectionDs(_))
00587         .Times(1)
00588         .WillOnce(Return(0));
00589 
00590     LabjackNode labjack_node(&mock);
00591 
00592     // success
00593     EXPECT_CALL(mock, writeIO(_, _))
00594         .Times(2)
00595         .WillRepeatedly(Return(0));
00596 
00597     ASSERT_EQ(0, labjack_node.setState(basic_states_skill_msgs::States::SLEEP_STATE));
00598 
00599     EXPECT_CALL(mock, writeIO(_, _))
00600         .Times(2)
00601         .WillRepeatedly(Return(0));
00602 
00603     ASSERT_EQ(0, labjack_node.setState(basic_states_skill_msgs::States::STOP_STATE));
00604 
00605     EXPECT_CALL(mock, writeIO(_, _))
00606         .Times(2)
00607         .WillRepeatedly(Return(0));
00608 
00609     ASSERT_EQ(0, labjack_node.setState(basic_states_skill_msgs::States::ACTIVE_STATE));
00610 
00611     // fail
00612     EXPECT_CALL(mock, writeIO(_, _))
00613         .Times(1)
00614         .WillOnce(Return(-1));
00615 
00616     ASSERT_EQ(-1, labjack_node.setState(basic_states_skill_msgs::States::SLEEP_STATE));
00617 
00618     ASSERT_EQ(-1, labjack_node.setState(10));
00619 }
00620 
00621 // Test enableBase()
00622 TEST(LabjackNode, EnableBase)
00623 {
00624     MockLjacklmWrapper mock;
00625 
00626     EXPECT_CALL(mock, config())
00627         .Times(1)
00628         .WillOnce(Return(0));
00629     EXPECT_CALL(mock, readDIOs(_, _))
00630         .Times(1)
00631         .WillOnce(Return(0));
00632     EXPECT_CALL(mock, readAIs(_, _, _))
00633         .Times(2)
00634         .WillRepeatedly(Return(0));
00635     EXPECT_CALL(mock, readDirectionDs(_))
00636         .Times(1)
00637         .WillOnce(Return(0));
00638 
00639     LabjackNode labjack_node(&mock);
00640 
00641     // success
00642     EXPECT_CALL(mock, writeIO(_, 0))
00643         .Times(1)
00644         .WillRepeatedly(Return(0));
00645 
00646     ASSERT_EQ(0, labjack_node.enableBase(true));
00647 
00648     EXPECT_CALL(mock, writeIO(_, 1))
00649         .Times(1)
00650         .WillRepeatedly(Return(0));
00651 
00652     ASSERT_EQ(0, labjack_node.enableBase(false));
00653 
00654     // fail
00655     EXPECT_CALL(mock, writeIO(_, 0))
00656         .Times(1)
00657         .WillRepeatedly(Return(-1));
00658 
00659     ASSERT_EQ(-1, labjack_node.enableBase(true));
00660 
00661     EXPECT_CALL(mock, writeIO(_, 1))
00662         .Times(1)
00663         .WillRepeatedly(Return(-1));
00664 
00665     ASSERT_EQ(-1, labjack_node.enableBase(false));
00666 }
00667 
00668 // Test enableBody()
00669 TEST(LabjackNode, EnableBody)
00670 {
00671     MockLjacklmWrapper mock;
00672 
00673     EXPECT_CALL(mock, config())
00674         .Times(1)
00675         .WillOnce(Return(0));
00676     EXPECT_CALL(mock, readDIOs(_, _))
00677         .Times(1)
00678         .WillOnce(Return(0));
00679     EXPECT_CALL(mock, readAIs(_, _, _))
00680         .Times(2)
00681         .WillRepeatedly(Return(0));
00682     EXPECT_CALL(mock, readDirectionDs(_))
00683         .Times(1)
00684         .WillOnce(Return(0));
00685 
00686     LabjackNode labjack_node(&mock);
00687 
00688     // success
00689     EXPECT_CALL(mock, writeIO(_, 0))
00690         .Times(1)
00691         .WillRepeatedly(Return(0));
00692 
00693     ASSERT_EQ(0, labjack_node.enableBody(true));
00694 
00695     EXPECT_CALL(mock, writeIO(_, 1))
00696         .Times(1)
00697         .WillRepeatedly(Return(0));
00698 
00699     ASSERT_EQ(0, labjack_node.enableBody(false));
00700 
00701     // fail
00702     EXPECT_CALL(mock, writeIO(_, 0))
00703         .Times(1)
00704         .WillRepeatedly(Return(-1));
00705 
00706     ASSERT_EQ(-1, labjack_node.enableBody(true));
00707 
00708     EXPECT_CALL(mock, writeIO(_, 1))
00709         .Times(1)
00710         .WillRepeatedly(Return(-1));
00711 
00712     ASSERT_EQ(-1, labjack_node.enableBody(false));
00713 }
00714 
00715 // Test setWatchdog()
00716 TEST(LabjackNode, setWatchdog)
00717 {
00718     MockLjacklmWrapper mock;
00719 
00720     EXPECT_CALL(mock, config())
00721         .Times(1)
00722         .WillOnce(Return(0));
00723     EXPECT_CALL(mock, readDIOs(_, _))
00724         .Times(1)
00725         .WillOnce(Return(0));
00726     EXPECT_CALL(mock, readAIs(_, _, _))
00727         .Times(2)
00728         .WillRepeatedly(Return(0));
00729     EXPECT_CALL(mock, readDirectionDs(_))
00730         .Times(1)
00731         .WillOnce(Return(0));
00732 
00733     LabjackNode labjack_node(&mock);
00734 
00735     // success
00736     EXPECT_CALL(mock, enableWatchdog(_, _, _))
00737         .Times(1)
00738         .WillOnce(Return(0));
00739 
00740     ASSERT_EQ(0, labjack_node.setWatchdog());
00741 
00742     // fail
00743     EXPECT_CALL(mock, enableWatchdog(_, _, _))
00744         .Times(1)
00745         .WillOnce(Return(-1));
00746 
00747     ASSERT_EQ(-1, labjack_node.setWatchdog());
00748 }
00749 
00750 // Test clearWatchdog()
00751 TEST(LabjackNode, ClearWatchdog)
00752 {
00753     MockLjacklmWrapper mock;
00754 
00755     EXPECT_CALL(mock, config())
00756         .Times(1)
00757         .WillOnce(Return(0));
00758     EXPECT_CALL(mock, readDIOs(_, _))
00759         .Times(1)
00760         .WillOnce(Return(0));
00761     EXPECT_CALL(mock, readAIs(_, _, _))
00762         .Times(2)
00763         .WillRepeatedly(Return(0));
00764     EXPECT_CALL(mock, readDirectionDs(_))
00765         .Times(1)
00766         .WillOnce(Return(0));
00767 
00768     LabjackNode labjack_node(&mock);
00769 
00770     // success
00771     EXPECT_CALL(mock, disableWatchdog(_))
00772         .Times(1)
00773         .WillOnce(Return(0));
00774 
00775     ASSERT_EQ(0, labjack_node.clearWatchdog());
00776 
00777     // fail
00778     EXPECT_CALL(mock, disableWatchdog(_))
00779         .Times(1)
00780         .WillOnce(Return(-1));
00781 
00782     ASSERT_EQ(-1, labjack_node.clearWatchdog());
00783 }
00784 
00785 // Test isEmergency()
00786 TEST(LabjackNode, IsEmergency)
00787 {
00788     MockLjacklmWrapper mock;
00789 
00790     EXPECT_CALL(mock, config())
00791         .Times(1)
00792         .WillOnce(Return(0));
00793     EXPECT_CALL(mock, readDIOs(_, _))
00794         .Times(1)
00795         .WillOnce(Return(0));
00796     EXPECT_CALL(mock, readAIs(_, _, _))
00797         .Times(2)
00798         .WillRepeatedly(Return(0));
00799     EXPECT_CALL(mock, readDirectionDs(_))
00800         .Times(1)
00801         .WillOnce(Return(0));
00802 
00803     LabjackNode labjack_node(&mock);
00804 
00805     // success
00806     EXPECT_CALL(mock, readDIOs(_, _))
00807         .Times(1)
00808         .WillOnce(Return(0));
00809 
00810     ASSERT_EQ(0, labjack_node.isEmergency());
00811 
00812     // fail
00813     EXPECT_CALL(mock, readDIOs(_, _))
00814         .Times(1)
00815         .WillOnce(Return(-1));
00816 
00817     ASSERT_EQ(1, labjack_node.isEmergency());
00818 }
00819 
00820 // Test setEmergency()
00821 TEST(LabjackNode, SetEmergency)
00822 {
00823     MockLjacklmWrapper mock;
00824 
00825     EXPECT_CALL(mock, config())
00826         .Times(1)
00827         .WillOnce(Return(0));
00828     EXPECT_CALL(mock, readDIOs(_, _))
00829         .Times(1)
00830         .WillOnce(Return(0));
00831     EXPECT_CALL(mock, readAIs(_, _, _))
00832         .Times(2)
00833         .WillRepeatedly(Return(0));
00834     EXPECT_CALL(mock, readDirectionDs(_))
00835         .Times(1)
00836         .WillOnce(Return(0));
00837 
00838     LabjackNode labjack_node(&mock);
00839 
00840     // success
00841     EXPECT_CALL(mock, writePulse(_, _, _, _))
00842         .Times(1)
00843         .WillOnce(Return(0));
00844     EXPECT_CALL(mock, writeIO(_, _))
00845         .Times(2)
00846         .WillRepeatedly(Return(0));
00847 
00848     ASSERT_EQ(0, labjack_node.setEmergency());
00849 
00850     // fail
00851     EXPECT_CALL(mock, writePulse(_, _, _, _))
00852         .Times(1)
00853         .WillOnce(Return(-1));
00854 
00855     ASSERT_EQ(-1, labjack_node.setEmergency());
00856 
00857     EXPECT_CALL(mock, writePulse(_, _, _, _))
00858         .Times(1)
00859         .WillOnce(Return(0));
00860     EXPECT_CALL(mock, writeIO(_, _))
00861         .Times(1)
00862         .WillOnce(Return(-1));
00863 
00864     ASSERT_EQ(-1, labjack_node.setEmergency());
00865 }
00866 
00867 // Test getVoltage()
00868 TEST(LabjackNode, GetVoltage)
00869 {
00870     MockLjacklmWrapper mock;
00871 
00872     EXPECT_CALL(mock, config())
00873         .Times(1)
00874         .WillOnce(Return(0));
00875     EXPECT_CALL(mock, readDIOs(_, _))
00876         .Times(1)
00877         .WillOnce(Return(0));
00878     EXPECT_CALL(mock, readAIs(_, _, _))
00879         .Times(2)
00880         .WillRepeatedly(Return(0));
00881     EXPECT_CALL(mock, readDirectionDs(_))
00882         .Times(1)
00883         .WillOnce(Return(0));
00884 
00885     LabjackNode labjack_node(&mock);
00886 
00887     // success
00888     EXPECT_CALL(mock, readAI(_, _))
00889         .Times(1)
00890         .WillOnce(Return(0));
00891 
00892     ASSERT_EQ(0, labjack_node.getVoltage());
00893 
00894     // fail
00895     EXPECT_CALL(mock, readAI(_, _))
00896         .Times(1)
00897         .WillOnce(Return(-1));
00898 
00899     ASSERT_FLOAT_EQ(-1, labjack_node.getVoltage());
00900 }
00901 
00902 // Test isPlugged()
00903 TEST(LabjackNode, IsPlugged)
00904 {
00905     MockLjacklmWrapper mock;
00906 
00907     EXPECT_CALL(mock, config())
00908         .Times(1)
00909         .WillOnce(Return(0));
00910     EXPECT_CALL(mock, readDIOs(_, _))
00911         .Times(1)
00912         .WillOnce(Return(0));
00913     EXPECT_CALL(mock, readAIs(_, _, _))
00914         .Times(2)
00915         .WillRepeatedly(Return(0));
00916     EXPECT_CALL(mock, readDirectionDs(_))
00917         .Times(1)
00918         .WillOnce(Return(0));
00919 
00920     LabjackNode labjack_node(&mock);
00921 
00922     // fail
00923     EXPECT_CALL(mock, readAI(_, _))
00924         .Times(1)
00925         .WillOnce(Return(-1));
00926 
00927     ASSERT_FALSE(labjack_node.isPlugged());
00928 }
00929 
00931 
00932 int main(int argc, char **argv)
00933 {
00934     ros::init(argc, argv, "labjack_node_tests");
00935 
00936     testing::InitGoogleMock(&argc, argv);
00937 
00938     return RUN_ALL_TESTS();
00939 }


maggie_labjack
Author(s): Raul Perula-Martinez
autogenerated on Thu Apr 23 2015 22:19:17