Skip to content

Instantly share code, notes, and snippets.

@codeporting-com-gists
Last active May 30, 2019 06:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codeporting-com-gists/6fda4928a331ad8c9de13d81f6cc5274 to your computer and use it in GitHub Desktop.
Save codeporting-com-gists/6fda4928a331ad8c9de13d81f6cc5274 to your computer and use it in GitHub Desktop.
This Gist contains examples of codeporting.com Blog Posts
CodePorting-Blog-Examples
#include "SimpleNUnitTest.h"
#include <testing/test_case_data.h>
#include <system/shared_ptr.h>
#include <system/object.h>
#include <system/collections/list.h>
#include <cstdint>
namespace PortingSln {
System::SharedPtr<System::Collections::Generic::IEnumerable<System::SharedPtr<NUnit::Framework::TestCaseData<int32_t, int32_t, int32_t>>>> MyTests::get_DivisionData()
{
auto result = [&]{ System::SharedPtr<NUnit::Framework::TestCaseData<int32_t, int32_t, int32_t>> init_0[] = {System::MakeObject<NUnit::Framework::TestCaseData<int32_t, int32_t, int32_t>>(12, 3)->Returns(4), System::MakeObject<NUnit::Framework::TestCaseData<int32_t, int32_t, int32_t>>(12, 2)->Returns(6), System::MakeObject<NUnit::Framework::TestCaseData<int32_t, int32_t, int32_t>>(12, 4)->Returns(3)}; auto list_0 = System::MakeObject<System::Collections::Generic::List<System::SharedPtr<NUnit::Framework::TestCaseData<int32_t, int32_t, int32_t>>>>(); list_0->AddInitializer(3, init_0); return list_0; }();
return result;
}
namespace gtest_test
{
class MyTests : public ::testing::Test
{
protected:
static System::SharedPtr<::PortingSln::MyTests> s_instance;
public:
static void SetUpTestCase()
{
s_instance = System::MakeObject<::PortingSln::MyTests>();
};
static void TearDownTestCase()
{
s_instance = nullptr;
};
};
System::SharedPtr<::PortingSln::MyTests> MyTests::s_instance;
} // namespece gtest_test
int32_t MyTests::DivideTest(int32_t n, int32_t d)
{
return n / d;
}
namespace gtest_test
{
using DivideTest_Args = System::SharedPtr<NUnit::Framework::TestCaseData<int32_t, int32_t, int32_t>>;
struct DivideTestVP : public MyTests, public PortingSln::MyTests, public ::testing::WithParamInterface<DivideTest_Args>
{
TEST_IF_STATIC_METHOD(DivisionData);
TEST_IF_CASE_HAS(field, DivisionData);
template<typename T, typename = typename std::enable_if<has_field<T>::value && !is_static_method<T>::value, T>::type>
static const auto GetTestCases() { return T::DivisionData; }
TEST_IF_CASE_HAS(method, DivisionData());
template<typename T, typename = typename std::enable_if<has_method<T>::value && is_static_method<T>::value, T>::type>
static const auto GetTestCases(int i = 0) { return T::DivisionData(); }
TEST_IF_CASE_HAS(property, get_DivisionData());
template<typename T, typename = typename std::enable_if<has_property<T>::value, T>::type>
static const auto GetTestCases(char c = 0) { return T::get_DivisionData(); }
static System::IEnumerableDefaultAdapter<DivideTest_Args> TestCases()
{
return System::IEnumerableDefaultAdapter<DivideTest_Args>(GetTestCases<DivideTestVP>());
}
};
TEST_P(DivideTestVP, Test)
{
const auto& params = GetParam();
ASSERT_NO_FATAL_FAILURE(params->test([](auto arg1, auto arg2)->int32_t { return s_instance->DivideTest(arg1, arg2); }));
}
INSTANTIATE_TEST_SUITE_P(MyTests, DivideTestVP, ::testing::ValuesIn(DivideTestVP::TestCases()));
} // namespece gtest_test
} // namespace PortingSln
using NUnit.Framework;
using System.Collections.Generic;
namespace PortingSln
{
[TestFixture]
public class MyTests
{
[TestCaseSource("DivisionData")]
public int DivideTest(int n, int d)
{
return n / d;
}
public static IEnumerable<TestCaseData> DivisionData
{
get
{
var result = new List<TestCaseData>()
{
new TestCaseData(12, 3).Returns(4),
new TestCaseData(12, 2).Returns(6),
new TestCaseData(12, 4).Returns(3)
};
return result;
}
}
}
}
#include <testing/test_case_data.h>
#include <system/test_tools/test_tools.h>
#include <system/test_tools/method_argument_tuple.h>
#include <system/shared_ptr.h>
#include <system/object.h>
#include <system/collections/ienumerable.h>
#include <gtest/gtest.h>
#include <cstdint>
namespace PortingSln {
class MyTests : public System::Object
{
public:
static System::SharedPtr<System::Collections::Generic::IEnumerable<System::SharedPtr<NUnit::Framework::TestCaseData<int32_t, int32_t, int32_t>>>> get_DivisionData();
int32_t DivideTest(int32_t n, int32_t d);
};
} // namespace PortingSln
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment