Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: Refactor driver error assertions #933

Merged
merged 6 commits into from
May 25, 2023

Conversation

bkeryan
Copy link
Contributor

@bkeryan bkeryan commented May 19, 2023

What does this Pull Request accomplish?

Add new assertion macros and helper functions to test_helpers.h:

  • EXPECT_THROW_DRIVER_ERROR
  • EXPECT_THROW_DRIVER_ERROR_WITH_SUBSTR
  • EXPECT_DRIVER_ERROR
    • Replaces expect_driver_error helper function
  • EXPECT_DRIVER_ERROR_WITH_SUBSTR
  • get_driver_error():
    • Accepts both gRPC metadata multimap types and grpc_driver_error exception
    • Returns int.
    • If the ni-error key is not found, get_driver_error() fails the test and returns 0.

Why should this Pull Request be merged?

Reduce boilerplate and increase consistency in tests.

What testing has been done?

Built on Windows and Linux.
Ran DAQmx tests on Windows.

bkeryan added 2 commits May 19, 2023 13:41
Signed-off-by: Brad Keryan <brad.keryan@ni.com>
Signed-off-by: Brad Keryan <brad.keryan@ni.com>
Copy link
Collaborator

@astarche astarche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks really good!

@bkeryan
Copy link
Contributor Author

bkeryan commented May 19, 2023

FYI, EXPECT_THAT(x, Optional(y)) prints the inner value even when gtest's PrintTo(const std::optional<T>&) overload is not available, but it also prints the std::optional as a bunch of bytes:

[ RUN      ] NiDAQmxDriverApiTests.AOVoltageChannel_WriteAODataWithOutOfRangeValue_ReturnsInvalidAODataError
C:\Dev\grpc-device\source\tests\system\nidaqmx_driver_api_tests.cpp(1170): error: Value of: driver_error
Expected: value is equal to -200560
  Actual: 8-byte object <8F-F0 FC-FF 01-CC CC-CC>, whose value -200561 doesn't match
[  FAILED  ] NiDAQmxDriverApiTests.AOVoltageChannel_WriteAODataWithOutOfRangeValue_ReturnsInvalidAODataError (19 ms)

Copy link
Contributor

@SparkingSpork SparkingSpork left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declining to review since I'm not code owner on any of the files now.

bkeryan added 2 commits May 20, 2023 11:27
Signed-off-by: Brad Keryan <brad.keryan@ni.com>
Signed-off-by: Brad Keryan <brad.keryan@ni.com>
@bkeryan bkeryan merged commit 462a79f into main May 25, 2023
@bkeryan bkeryan deleted the users/bkeryan/driver-error-test-assertions branch May 25, 2023 12:13

#include "client_helpers.h"

inline void expect_driver_error(const nidevice_grpc::experimental::client::grpc_driver_error& ex, int32_t expected_error)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This broke the build because I added new calls to this function in #928. Fixed in #939

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants