Skip to content

Commit

Permalink
Updated motifCpp and guid liblets from RNW Mso fork (#40)
Browse files Browse the repository at this point in the history
* Updated mortifCpp and guid liblets from RNW Mso fork

* Change files

* Removed unused ExpectException override.
  • Loading branch information
vmoroz authored Apr 5, 2020
1 parent d9687f8 commit 61f55be
Show file tree
Hide file tree
Showing 10 changed files with 630 additions and 314 deletions.
4 changes: 2 additions & 2 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"${workspaceFolder}/libs/compilerAdapters/include",
"${workspaceFolder}/libs/comUtil/include",
"${workspaceFolder}/libs/cppExtensions/include",
Expand All @@ -21,7 +20,8 @@
"${workspaceFolder}/libs/platform_posix/include",
"${workspaceFolder}/libs/smartPtr/include",
"${workspaceFolder}/libs/tagUtils/include",
"${workspaceFolder}/libs/typeTraits/include"
"${workspaceFolder}/libs/typeTraits/include",
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "/usr/bin/clang",
Expand Down
13 changes: 12 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,16 @@
"search.exclude": {
"**/node_modules": true,
"**/dist": true
}
},
"cSpell.words": [
"GTEST",
"HRESULT",
"MOTIFCPP",
"MOTIFCPPTEST",
"OACR",
"STREQ",
"STRNE",
"XCTEST",
"unwinded"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"type": "patch",
"comment": "Updated mortifCpp and guid liblets from RNW Mso fork",
"packageName": "@microsoft/mso",
"email": "[email protected]",
"dependentChangeType": "patch",
"date": "2020-04-05T22:48:50.448Z"
}
6 changes: 5 additions & 1 deletion external/gtest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ if(MSO_ENABLE_UNIT_TESTS)
# the following code to fetch googletest
# is inspired by and adapted after:
# - https://cmake.org/cmake/help/v3.11/module/FetchContent.html
#
# We use version of GTest as in the https://github.com/Microsoft/TestAdapterForGoogleTest
# It allows to run GTests in Visual Studio and ADO.
# Please update the GIT_TAG below after the TAFGT is updated the reference.
include(FetchContent)

FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG origin/master
GIT_TAG 2fe3bd994b3189899d93f1d5a881e725e046fdc2
GIT_SHALLOW 1
GIT_PROGRESS 1
)
Expand Down
1 change: 1 addition & 0 deletions libs/cppExtensions/include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

liblet_includes(
INCLUDES
cppExtensions/array.h
cppExtensions/autoRestore.h
cppExtensions/stringLiteral.h
INCLUDES_WIN
Expand Down
21 changes: 21 additions & 0 deletions libs/cppExtensions/include/cppExtensions/array.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

#pragma once
#ifndef MSO_CPPEXTENSIONS_AUTORESTORE_H
#define MSO_CPPEXTENSIONS_AUTORESTORE_H

#include <cstddef>

namespace Mso {
//! Return compile-time size of an array.
//! It can be used instead of MSVC _countof macro
template <class T, size_t N>
constexpr size_t SizeOf([[maybe_unused]] T (&arr)[N]) noexcept
{
return N;
}

} // namespace Mso

#endif // MSO_CPPEXTENSIONS_AUTORESTORE_H
173 changes: 88 additions & 85 deletions libs/guid/tests/guidTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <guid/msoGuid.h>
#include <motifCpp/testCheck.h>
#include <compilerAdapters/declspecDefinitions.h>
#include <cppExtensions/array.h>

MSO_STRUCT_GUID(IBaseInterface, "38E23DC7-92B1-4B21-B5FE-6EA786817915")
struct DECLSPEC_NOVTABLE IBaseInterface
Expand Down Expand Up @@ -99,90 +100,92 @@ MSO_DEFINE_GUID_TOKEN(MyProductId2, "AABFD353-B463-41A2-B04C-9A6AB7541D20")

MSO_DEFINE_GUID_TOKEN(FailingToParseId, "A39D5FC8-0641-4EEE-8C97-DDEF114D487D")

#if 0
TEST_CLASS (GuidTest){
static std::string GuidToString(const GUID& guid){char str[37];
sprintf_s(
str,
_countof(str),
"%08lX-%04hX-%04hX-%02hhX%02hhX-%02hhX%02hhX%02hhX%02hhX%02hhX%02hhX",
guid.Data1,
guid.Data2,
guid.Data3,
guid.Data4[0],
guid.Data4[1],
guid.Data4[2],
guid.Data4[3],
guid.Data4[4],
guid.Data4[5],
guid.Data4[6],
guid.Data4[7]);
return str;
}

TEST_METHOD(TestTypeGuids)
TEST_CLASS (GuidTest)
{
TestAssert::AreEqual(std::string("38E23DC7-92B1-4B21-B5FE-6EA786817915"), GuidToString(__uuidof(IBaseInterface)));
TestAssert::AreEqual(std::string("9E11BC42-1416-45B1-9712-AA4AAD87F78B"), GuidToString(__uuidof(IDerivedInterface)));
TestAssert::AreEqual(std::string("866E3389-0194-4416-94CE-6BE8A5185387"), GuidToString(__uuidof(MyClass)));
TestAssert::AreEqual(
std::string("BAA524C8-F5D1-4CE7-AE24-1FF5EAB306B2"), GuidToString(__uuidof(AlreadyDefinedType1)));
TestAssert::AreEqual(
std::string("8C76ECFE-0715-4DA1-9746-2FD4DE39118F"), GuidToString(__uuidof(AlreadyDefinedType2)));
}

TEST_METHOD(TestTypeGuids_InNamespace)
{
TestAssert::AreEqual(
std::string("86DE7178-00E6-4A40-8B2C-BA2FBFFB4D06"),
GuidToString(__uuidof(MyAppTest::MyDetails::IBaseInterface2)));
TestAssert::AreEqual(
std::string("C91CAD11-98AB-4218-952F-87509F8F2116"),
GuidToString(__uuidof(MyAppTest::MyDetails::IDerivedInterface2)));
TestAssert::AreEqual(
std::string("06A68045-D24C-4816-84DC-C18888EC46A9"), GuidToString(__uuidof(MyAppTest::MyDetails::MyClass2)));
TestAssert::AreEqual(
std::string("6B2050DF-6C60-48ED-809D-A88B2476E5A2"),
GuidToString(__uuidof(MyAppTest::MyDetails::AlreadyDefinedType21)));
TestAssert::AreEqual(
std::string("78CEA0B9-2AC5-4FD0-8EE8-C02836BE800D"),
GuidToString(__uuidof(MyAppTest::MyDetails::AlreadyDefinedType22)));
}

TEST_METHOD(TestTypeGuids_uuidof_AsTemplateParameter)
{
auto h1 = MyGuidHolder<__uuidof(IBaseInterface)>();
TestAssert::AreEqual(std::string("38E23DC7-92B1-4B21-B5FE-6EA786817915"), GuidToString(h1.GetGuid()));
auto h2 = MyGuidHolder<__uuidof(MyAppTest::MyDetails::IBaseInterface2)>();
TestAssert::AreEqual(std::string("86DE7178-00E6-4A40-8B2C-BA2FBFFB4D06"), GuidToString(h2.GetGuid()));
}
static std::string GuidToString(const GUID& guid)
{
char str[37];
snprintf(
str,
Mso::SizeOf(str),
"%08X-%04hX-%04hX-%02hhX%02hhX-%02hhX%02hhX%02hhX%02hhX%02hhX%02hhX",
guid.Data1,
guid.Data2,
guid.Data3,
guid.Data4[0],
guid.Data4[1],
guid.Data4[2],
guid.Data4[3],
guid.Data4[4],
guid.Data4[5],
guid.Data4[6],
guid.Data4[7]);
return str;
}

TEST_METHOD(TestTypeGuids_TypeHasGuid)
{
TestAssert::IsTrue(Mso::TypeHasGuid<IBaseInterface>::Value);
TestAssert::IsTrue(Mso::TypeHasGuid<IDerivedInterface>::Value);
TestAssert::IsTrue(Mso::TypeHasGuid<MyClass>::Value);
TestAssert::IsTrue(Mso::TypeHasGuid<AlreadyDefinedType1>::Value);
TestAssert::IsTrue(Mso::TypeHasGuid<AlreadyDefinedType2>::Value);
TestAssert::IsFalse(Mso::TypeHasGuid<TypeWithoutGuid>::Value);

TestAssert::IsTrue(Mso::TypeHasGuid<MyAppTest::MyDetails::IBaseInterface2>::Value);
TestAssert::IsTrue(Mso::TypeHasGuid<MyAppTest::MyDetails::IDerivedInterface2>::Value);
TestAssert::IsTrue(Mso::TypeHasGuid<MyAppTest::MyDetails::MyClass2>::Value);
TestAssert::IsTrue(Mso::TypeHasGuid<MyAppTest::MyDetails::AlreadyDefinedType21>::Value);
TestAssert::IsTrue(Mso::TypeHasGuid<MyAppTest::MyDetails::AlreadyDefinedType22>::Value);
TestAssert::IsFalse(Mso::TypeHasGuid<MyAppTest::MyDetails::TypeWithoutGuid2>::Value);
}

TEST_METHOD(TestTypeGuids_DefineGuidToken)
{
TestAssert::AreEqual(std::string("67A42775-79F7-469D-8A28-7348ED9F8D71"), GuidToString(__uuidof_token(MyProductId)));
TestAssert::AreEqual(
std::string("AABFD353-B463-41A2-B04C-9A6AB7541D20"),
GuidToString(__uuidof_token(MyAppTest::MyDetails::MyProductId2)));
TestAssert::AreEqual(
std::string("A39D5FC8-0641-4EEE-8C97-DDEF114D487D"), GuidToString(__uuidof_token(FailingToParseId)));
}
}
;
#endif
TEST_METHOD(TestTypeGuids)
{
TestAssert::AreEqual(std::string("38E23DC7-92B1-4B21-B5FE-6EA786817915"), GuidToString(__uuidof(IBaseInterface)));
TestAssert::AreEqual(
std::string("9E11BC42-1416-45B1-9712-AA4AAD87F78B"), GuidToString(__uuidof(IDerivedInterface)));
TestAssert::AreEqual(std::string("866E3389-0194-4416-94CE-6BE8A5185387"), GuidToString(__uuidof(MyClass)));
TestAssert::AreEqual(
std::string("BAA524C8-F5D1-4CE7-AE24-1FF5EAB306B2"), GuidToString(__uuidof(AlreadyDefinedType1)));
TestAssert::AreEqual(
std::string("8C76ECFE-0715-4DA1-9746-2FD4DE39118F"), GuidToString(__uuidof(AlreadyDefinedType2)));
}

TEST_METHOD(TestTypeGuids_InNamespace)
{
TestAssert::AreEqual(
std::string("86DE7178-00E6-4A40-8B2C-BA2FBFFB4D06"),
GuidToString(__uuidof(MyAppTest::MyDetails::IBaseInterface2)));
TestAssert::AreEqual(
std::string("C91CAD11-98AB-4218-952F-87509F8F2116"),
GuidToString(__uuidof(MyAppTest::MyDetails::IDerivedInterface2)));
TestAssert::AreEqual(
std::string("06A68045-D24C-4816-84DC-C18888EC46A9"), GuidToString(__uuidof(MyAppTest::MyDetails::MyClass2)));
TestAssert::AreEqual(
std::string("6B2050DF-6C60-48ED-809D-A88B2476E5A2"),
GuidToString(__uuidof(MyAppTest::MyDetails::AlreadyDefinedType21)));
TestAssert::AreEqual(
std::string("78CEA0B9-2AC5-4FD0-8EE8-C02836BE800D"),
GuidToString(__uuidof(MyAppTest::MyDetails::AlreadyDefinedType22)));
}

TEST_METHOD(TestTypeGuids_uuidof_AsTemplateParameter)
{
auto h1 = MyGuidHolder<__uuidof(IBaseInterface)>();
TestAssert::AreEqual(std::string("38E23DC7-92B1-4B21-B5FE-6EA786817915"), GuidToString(h1.GetGuid()));
auto h2 = MyGuidHolder<__uuidof(MyAppTest::MyDetails::IBaseInterface2)>();
TestAssert::AreEqual(std::string("86DE7178-00E6-4A40-8B2C-BA2FBFFB4D06"), GuidToString(h2.GetGuid()));
}

TEST_METHOD(TestTypeGuids_TypeHasGuid)
{
TestAssert::IsTrue(Mso::TypeHasGuid<IBaseInterface>::Value);
TestAssert::IsTrue(Mso::TypeHasGuid<IDerivedInterface>::Value);
TestAssert::IsTrue(Mso::TypeHasGuid<MyClass>::Value);
TestAssert::IsTrue(Mso::TypeHasGuid<AlreadyDefinedType1>::Value);
TestAssert::IsTrue(Mso::TypeHasGuid<AlreadyDefinedType2>::Value);
TestAssert::IsFalse(Mso::TypeHasGuid<TypeWithoutGuid>::Value);

TestAssert::IsTrue(Mso::TypeHasGuid<MyAppTest::MyDetails::IBaseInterface2>::Value);
TestAssert::IsTrue(Mso::TypeHasGuid<MyAppTest::MyDetails::IDerivedInterface2>::Value);
TestAssert::IsTrue(Mso::TypeHasGuid<MyAppTest::MyDetails::MyClass2>::Value);
TestAssert::IsTrue(Mso::TypeHasGuid<MyAppTest::MyDetails::AlreadyDefinedType21>::Value);
TestAssert::IsTrue(Mso::TypeHasGuid<MyAppTest::MyDetails::AlreadyDefinedType22>::Value);
TestAssert::IsFalse(Mso::TypeHasGuid<MyAppTest::MyDetails::TypeWithoutGuid2>::Value);
}

TEST_METHOD(TestTypeGuids_DefineGuidToken)
{
TestAssert::AreEqual(
std::string("67A42775-79F7-469D-8A28-7348ED9F8D71"), GuidToString(__uuidof_token(MyProductId)));
TestAssert::AreEqual(
std::string("AABFD353-B463-41A2-B04C-9A6AB7541D20"),
GuidToString(__uuidof_token(MyAppTest::MyDetails::MyProductId2)));
TestAssert::AreEqual(
std::string("A39D5FC8-0641-4EEE-8C97-DDEF114D487D"), GuidToString(__uuidof_token(FailingToParseId)));
}
};
Loading

0 comments on commit 61f55be

Please sign in to comment.