test: start frutils unit-tests
Add initial fruutils library unit-tests.
Signed-off-by: Patrick Venture <venture@google.com>
Change-Id: Ie02c1a968500d010daea747f61e818a2d110363b
diff --git a/meson.build b/meson.build
index 373b36c..e016f04 100644
--- a/meson.build
+++ b/meson.build
@@ -149,6 +149,7 @@
subdir('src')
if not build_tests.disabled()
+ test_boost_args = boost_args + ['-DBOOST_ASIO_DISABLE_THREADS']
gtest = dependency('gtest', main: true, disabler: true, required: false)
if not gtest.found() and build_tests.enabled()
cmake = import('cmake')
@@ -164,7 +165,7 @@
'test_entity_manager',
'test/test_entity-manager.cpp',
'src/Utils.cpp',
- cpp_args: boost_args + ['-DBOOST_ASIO_DISABLE_THREADS'],
+ cpp_args: test_boost_args,
dependencies: [
boost,
gtest,
@@ -176,4 +177,20 @@
include_directories: 'include',
)
)
+
+ test(
+ 'test_fru_utils',
+ executable(
+ 'test_fru_utils',
+ 'test/test_fru-utils.cpp',
+ 'src/FruUtils.cpp',
+ cpp_args: test_boost_args,
+ dependencies: [
+ boost,
+ gtest,
+ ],
+ implicit_include_directories: false,
+ include_directories: 'include',
+ )
+ )
endif
diff --git a/test/test_fru-utils.cpp b/test/test_fru-utils.cpp
new file mode 100644
index 0000000..4f4f57a
--- /dev/null
+++ b/test/test_fru-utils.cpp
@@ -0,0 +1,20 @@
+#include "FruUtils.hpp"
+
+#include <array>
+
+#include "gtest/gtest.h"
+
+extern "C"
+{
+// Include for I2C_SMBUS_BLOCK_MAX
+#include <linux/i2c.h>
+}
+
+TEST(ValidateHeaderTest, InvalidFruVersionReturnsFalse)
+{
+ // Validates the FruVersion is checked for the only legal value.
+ constexpr std::array<uint8_t, I2C_SMBUS_BLOCK_MAX> fru_header = {
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+
+ EXPECT_FALSE(validateHeader(fru_header));
+}