gtest: TYPED_TEST не компилируется - PullRequest
0 голосов
/ 04 августа 2020

с использованием gtest 1.10.0 Я пытаюсь заставить работать типизированные тесты.

typedef testing::Types<double, float> Implementations;
TYPED_TEST_SUITE(SphericalHarmonicsTest, Implementations);

TYPED_TEST(SphericalHarmonicsTest, ProjectFunction) {
  // The expected coefficients used to define the analytic spherical function
  const std::vector<TypeParam> coeffs = {static_cast<TypeParam>(-1.028),
                                         static_cast<TypeParam>(0.779),
                                         static_cast<TypeParam>(-0.275),
                                         static_cast<TypeParam>(0.601),
                                         static_cast<TypeParam>(-0.256),
                                         static_cast<TypeParam>(1.891),
                                         static_cast<TypeParam>(-1.658),
                                         static_cast<TypeParam>(-0.370),
                                         static_cast<TypeParam>(-0.772)};

  // Project and compare the fitted coefficients, which should be near identical
  // to the initial coefficients
  SphericalFunction<TypeParam, double> func = [&] (double phi, double theta) {
    return EvalSHSum(2, coeffs, phi, theta); };
  std::unique_ptr<std::vector<TypeParam>> fitted = ProjectFunction(
      2, func, kTestSampleCount);
  ASSERT_TRUE(fitted != nullptr);

  for (int i = 0; i < 9; i++) {
    EXPECT_NEAR(coeffs[i], (*fitted)[i], kCoeffErr);
  }
}

Я использую тот же синтаксис, что и в официальном примере https://github.com/google/googletest/blob/master/googletest/samples/sample6_unittest.cc#L76, но я Я получаю ошибки компилятора (используя MSV C):

sh/spherical_harmonics_test.cc(130): error C2143: syntax error: missing ',' before '<'
sh/spherical_harmonics_test.cc(130): note: see reference to class template instantiation 'sh::SphericalHarmonicsTest_ProjectFunction_Test<gtest_TypeParam_>' being compiled
sh/spherical_harmonics_test.cc(130): error C2143: syntax error: missing ';' before '<'
sh/spherical_harmonics_test.cc(130): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
sh/spherical_harmonics_test.cc(130): error C2238: unexpected token(s) preceding ';'
sh/spherical_harmonics_test.cc(130): error C2065: 'SphericalHarmonicsTest': undeclared identifier
sh/spherical_harmonics_test.cc(130): error C3200: 'unknown-type': invalid template argument for template parameter 'Fixture', expected a class template
sh/spherical_harmonics_test.cc(130): error C2955: 'testing::internal::TypeParameterizedTest': use of class template requires template argument list

строка 130: TYPED_TEST(SphericalHarmonicsTest, ProjectFunction) {

Нужно ли мне что-нибудь еще, чтобы это работало?

// редактировать: обратите внимание, что если я заменю TYPED_TEST на TEST и заменю все TypeParam на double или float, тогда тест будет работать. Так что тест в целом в порядке - просто шаблон с TYPED_TEST не работает.

...