test_message.cpp
Go to the documentation of this file.
00001 /*********************************************************************
00002  * C++ unit test for dataspeed_can_tools/DbcMessage.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/DbcMessage.hpp"
00014 
00015 // Check that parsing valid signals does not cause an error.
00016 TEST(MESSAGE, parsing)
00017 {
00018   Message msg;
00019   std::istringstream in;
00020 
00021   std::string input = "BO_ 126 License: 8 EPAS\n";
00022   input += " SG_ EXPIRED : 10|1@1+ (1,0) [0|0] \"\"  MAB\n";
00023   input += " SG_ MUX M : 0|8@1+ (1,0) [0|0] \"\"  MAB\n";
00024   input += " SG_ FEAT_BASE_TRIALS_USED m0 : 32|16@1+ (1,0) [0|0] \"\"  MAB\n";
00025   input += " SG_ DATE1 m129 : 24|8@1+ (1,0) [0|0] \"\"  MAB";
00026   in.str(input);
00027   in >> msg;
00028   ASSERT_FALSE(in.fail());
00029   in.clear();
00030 }
00031 
00032 // Check the values output by parsing valid signals.
00033 TEST(MESSAGE, data)
00034 {
00035   Message msg;
00036   std::istringstream in;
00037 
00038   std::string input = "BO_ 126 License: 8 EPAS\n";
00039   input += " SG_ EXPIRED : 10|1@1+ (1,0) [0|0] \"\"  MAB\n";
00040   input += " SG_ MUX M : 0|8@1+ (1,0) [0|0] \"\"  MAB\n";
00041   input += " SG_ FEAT_BASE_TRIALS_USED m0 : 32|16@1+ (1,0) [0|0] \"\"  MAB\n";
00042   input += " SG_ DATE1 m129 : 24|8@1+ (1,0) [0|0] \"\"  MAB";
00043   in.str(input);
00044   in >> msg;
00045   ASSERT_FALSE(in.fail());
00046   // Main
00047   EXPECT_EQ(msg.getId(), 126u);
00048   EXPECT_EQ(msg.getName(), "License");
00049   EXPECT_EQ(msg.getDlc(), 8u);
00050   EXPECT_EQ(msg.getFrom(), "EPAS");
00051   // sig[0]
00052   EXPECT_EQ(msg[0].getName(), "EXPIRED");
00053   EXPECT_EQ(msg[0].getMultiplexor(), NONE);
00054   //EXPECT_EQ(sig[0].getMultiplexedNumber(), 0);
00055   EXPECT_EQ(msg[0].getStartbit(), 10);
00056   EXPECT_EQ(msg[0].getLength(), 1);
00057   EXPECT_EQ(msg[0].getByteOrder(), INTEL);
00058   EXPECT_EQ(msg[0].getSign(), UNSIGNED);
00059   EXPECT_EQ(msg[0].getFactor(), 1);
00060   EXPECT_EQ(msg[0].getOffset(), 0);
00061   EXPECT_EQ(msg[0].getMinimum(), 0);
00062   EXPECT_EQ(msg[0].getMaximum(), 0);
00063   EXPECT_EQ(msg[0].getUnit(), "");
00064   // Receivers?
00065   // sig[1]
00066   EXPECT_EQ(msg[1].getName(), "MUX");
00067   EXPECT_EQ(msg[1].getMultiplexor(), MULTIPLEXOR);
00068   //EXPECT_EQ(msg[1].getMultiplexedNumber(), 0);
00069   EXPECT_EQ(msg[1].getStartbit(), 0);
00070   EXPECT_EQ(msg[1].getLength(), 8);
00071   EXPECT_EQ(msg[1].getByteOrder(), INTEL);
00072   EXPECT_EQ(msg[1].getSign(), UNSIGNED);
00073   EXPECT_EQ(msg[1].getFactor(), 1);
00074   EXPECT_EQ(msg[1].getOffset(), 0);
00075   EXPECT_EQ(msg[1].getMinimum(), 0);
00076   EXPECT_EQ(msg[1].getMaximum(), 0);
00077   EXPECT_EQ(msg[1].getUnit(), "");
00078   // Receivers?
00079   // sig[2]
00080   EXPECT_EQ(msg[2].getName(), "FEAT_BASE_TRIALS_USED");
00081   EXPECT_EQ(msg[2].getMultiplexor(), MULTIPLEXED);
00082   EXPECT_EQ(msg[2].getMultiplexedNumber(), 0);
00083   EXPECT_EQ(msg[2].getStartbit(), 32);
00084   EXPECT_EQ(msg[2].getLength(), 16);
00085   EXPECT_EQ(msg[2].getByteOrder(), INTEL);
00086   EXPECT_EQ(msg[2].getSign(), UNSIGNED);
00087   EXPECT_EQ(msg[2].getFactor(), 1);
00088   EXPECT_EQ(msg[2].getOffset(), 0);
00089   EXPECT_EQ(msg[2].getMinimum(), 0);
00090   EXPECT_EQ(msg[2].getMaximum(), 0);
00091   EXPECT_EQ(msg[2].getUnit(), "");
00092   // Receivers?
00093   // sig[3]
00094   EXPECT_EQ(msg[3].getName(), "DATE1");
00095   EXPECT_EQ(msg[3].getMultiplexor(), MULTIPLEXED);
00096   EXPECT_EQ(msg[3].getMultiplexedNumber(), 129);
00097   EXPECT_EQ(msg[3].getStartbit(), 24);
00098   EXPECT_EQ(msg[3].getLength(), 8);
00099   EXPECT_EQ(msg[3].getByteOrder(), INTEL);
00100   EXPECT_EQ(msg[3].getSign(), UNSIGNED);
00101   EXPECT_EQ(msg[3].getFactor(), 1);
00102   EXPECT_EQ(msg[3].getOffset(), 0);
00103   EXPECT_EQ(msg[3].getMinimum(), 0);
00104   EXPECT_EQ(msg[3].getMaximum(), 0);
00105   EXPECT_EQ(msg[3].getUnit(), "");
00106   // Receivers?
00107 
00108   in.clear();
00109 }
00110 
00111 int main(int argc, char **argv)
00112 {
00113   testing::InitGoogleTest(&argc, argv);
00114   return RUN_ALL_TESTS();
00115 }
00116 


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