test_signal.cpp
Go to the documentation of this file.
00001 /*********************************************************************
00002  * C++ unit test for dataspeed_can_tools/DbcSignal.hpp
00003  *********************************************************************/
00004 
00005 #include <gtest/gtest.h>
00006 
00007 // String stream
00008 #include <iostream>
00009 #include <sstream>
00010 #include <string>
00011 
00012 // File under test
00013 #include "../src/DbcSignal.hpp"
00014 
00015 // Check that parsing valid signals does not cause an error.
00016 TEST(SIGNAL, parsing)
00017 {
00018   Signal sig;
00019   std::istringstream in;
00020 
00021   // Normal (non-Multiplexed) bool
00022   in.str("SG_ TEST : 8|1@1+ (1,0) [0|0] \"\"  MAB");
00023   in >> sig;
00024   ASSERT_FALSE(in.fail());
00025   in.clear();
00026 
00027   // Multiplexed (0) bool
00028   in.str("SG_ FEAT_BASE_ENABLED m0 : 16|1@1+ (1,0) [0|0] \"\"  MAB");
00029   in >> sig;
00030   ASSERT_FALSE(in.fail());
00031   in.clear();
00032 
00033   // Multiplexor
00034   in.str("SG_ MUX M : 0|8@1+ (1,0) [0|0] \"\"  MAB");
00035   in >> sig;
00036   ASSERT_FALSE(in.fail());
00037   in.clear();
00038 
00039   // Multiplexed (129) short
00040   in.str("SG_ DATE1 m129 : 24|8@1+ (1,0) [0|0] \"\"  MAB");
00041   in >> sig;
00042   ASSERT_FALSE(in.fail());
00043   in.clear();
00044 }
00045 
00046 // Check the values output by parsing valid signals.
00047 TEST(SIGNAL, data)
00048 {
00049   Signal sig;
00050   std::istringstream in;
00051 
00052   // Normal (non-Multiplexed) bool
00053   in.str("SG_ TEST : 8|1@1+ (1,0) [0|0] \"\"  MAB");
00054   in >> sig;
00055   ASSERT_FALSE(in.fail());
00056   EXPECT_EQ(sig.getName(), "TEST");
00057   EXPECT_EQ(sig.getMultiplexor(), NONE);
00058   //EXPECT_EQ(sig.getMultiplexedNumber(), 0);
00059   EXPECT_EQ(sig.getStartbit(), 8);
00060   EXPECT_EQ(sig.getLength(), 1);
00061   EXPECT_EQ(sig.getByteOrder(), INTEL);
00062   EXPECT_EQ(sig.getSign(), UNSIGNED);
00063   EXPECT_EQ(sig.getFactor(), 1);
00064   EXPECT_EQ(sig.getOffset(), 0);
00065   EXPECT_EQ(sig.getMinimum(), 0);
00066   EXPECT_EQ(sig.getMaximum(), 0);
00067   EXPECT_EQ(sig.getUnit(), "");
00068   // Receivers?
00069   in.clear();
00070 
00071   // Multiplexed (0) bool
00072   in.str("SG_ FEAT_BASE_ENABLED m0 : 16|1@1+ (1,0) [0|0] \"\"  MAB");
00073   in >> sig;
00074   ASSERT_FALSE(in.fail());
00075   EXPECT_EQ(sig.getName(), "FEAT_BASE_ENABLED");
00076   EXPECT_EQ(sig.getMultiplexor(), MULTIPLEXED);
00077   EXPECT_EQ(sig.getMultiplexedNumber(), 0);
00078   EXPECT_EQ(sig.getStartbit(), 16);
00079   EXPECT_EQ(sig.getLength(), 1);
00080   EXPECT_EQ(sig.getByteOrder(), INTEL);
00081   EXPECT_EQ(sig.getSign(), UNSIGNED);
00082   EXPECT_EQ(sig.getFactor(), 1);
00083   EXPECT_EQ(sig.getOffset(), 0);
00084   EXPECT_EQ(sig.getMinimum(), 0);
00085   EXPECT_EQ(sig.getMaximum(), 0);
00086   EXPECT_EQ(sig.getUnit(), "");
00087   // Receivers?
00088   in.clear();
00089 
00090   // Multiplexor
00091   in.str("SG_ MUX M : 0|8@1+ (1,0) [0|0] \"\"  MAB");
00092   in >> sig;
00093   ASSERT_FALSE(in.fail());
00094   EXPECT_EQ(sig.getName(), "MUX");
00095   EXPECT_EQ(sig.getMultiplexor(), MULTIPLEXOR);
00096   //EXPECT_EQ(sig.getMultiplexedNumber(), 129);
00097   EXPECT_EQ(sig.getStartbit(), 0);
00098   EXPECT_EQ(sig.getLength(), 8);
00099   EXPECT_EQ(sig.getByteOrder(), INTEL);
00100   EXPECT_EQ(sig.getSign(), UNSIGNED);
00101   EXPECT_EQ(sig.getFactor(), 1);
00102   EXPECT_EQ(sig.getOffset(), 0);
00103   EXPECT_EQ(sig.getMinimum(), 0);
00104   EXPECT_EQ(sig.getMaximum(), 0);
00105   EXPECT_EQ(sig.getUnit(), "");
00106   // Receivers?
00107   in.clear();
00108 
00109   // Multiplexed (129) short
00110   in.str("SG_ DATE1 m129 : 24|8@1+ (1,0) [0|0] \"\"  MAB");
00111   in >> sig;
00112   ASSERT_FALSE(in.fail());
00113   EXPECT_EQ(sig.getName(), "DATE1");
00114   EXPECT_EQ(sig.getMultiplexor(), MULTIPLEXED);
00115   EXPECT_EQ(sig.getMultiplexedNumber(), 129);
00116   EXPECT_EQ(sig.getStartbit(), 24);
00117   EXPECT_EQ(sig.getLength(), 8);
00118   EXPECT_EQ(sig.getByteOrder(), INTEL);
00119   EXPECT_EQ(sig.getSign(), UNSIGNED);
00120   EXPECT_EQ(sig.getFactor(), 1);
00121   EXPECT_EQ(sig.getOffset(), 0);
00122   EXPECT_EQ(sig.getMinimum(), 0);
00123   EXPECT_EQ(sig.getMaximum(), 0);
00124   EXPECT_EQ(sig.getUnit(), "");
00125   // Receivers?
00126   in.clear();
00127 }
00128 
00129 int main(int argc, char **argv)
00130 {
00131   testing::InitGoogleTest(&argc, argv);
00132   return RUN_ALL_TESTS();
00133 }
00134 


dataspeed_can_tools
Author(s): Micho Radovnikovich
autogenerated on Thu Jun 6 2019 21:16:41