Add an implementation of Result<const T*, E*>

The existing implementation of Result with tagged pointers was not able
to handle constant pointers for the result. This is required in
follow-up CLs to return internal formats in a ResultOrError.

This CL extracts the tagged pointer logic out of Result<T*, E*> so it
can be shared with Result<const T*, E*>.

Tests are also added to cover Result<const T*, E*>.

BUG=dawn:128

Change-Id: Id19ae8e1153bcfcaf94d95ac314faf2b23af6f91
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/9100
Commit-Queue: Kai Ninomiya <kainino@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
This commit is contained in:
Corentin Wallez
2019-07-17 19:01:50 +00:00
committed by Commit Bot service account
parent 9dbb81f004
commit d6cc1fe099
4 changed files with 191 additions and 37 deletions

View File

@@ -38,6 +38,7 @@ void TestSuccess(Result<T, E>* result, T expectedSuccess) {
static int dummyError = 0xbeef;
static float dummySuccess = 42.0f;
static const float dummyConstSuccess = 42.0f;
// Result<void, E*>
@@ -138,6 +139,50 @@ TEST(ResultBothPointer, ReturningSuccess) {
TestSuccess(&result, &dummySuccess);
}
// Result<const T*, E*>
// Test constructing an error Result<const T*, E*>
TEST(ResultBothPointerWithConstResult, ConstructingError) {
Result<const float*, int*> result(&dummyError);
TestError(&result, &dummyError);
}
// Test moving an error Result<const T*, E*>
TEST(ResultBothPointerWithConstResult, MovingError) {
Result<const float*, int*> result(&dummyError);
Result<const float*, int*> movedResult(std::move(result));
TestError(&movedResult, &dummyError);
}
// Test returning an error Result<const T*, E*>
TEST(ResultBothPointerWithConstResult, ReturningError) {
auto CreateError = []() -> Result<const float*, int*> { return {&dummyError}; };
Result<const float*, int*> result = CreateError();
TestError(&result, &dummyError);
}
// Test constructing a success Result<const T*, E*>
TEST(ResultBothPointerWithConstResult, ConstructingSuccess) {
Result<const float*, int*> result(&dummyConstSuccess);
TestSuccess(&result, &dummyConstSuccess);
}
// Test moving a success Result<const T*, E*>
TEST(ResultBothPointerWithConstResult, MovingSuccess) {
Result<const float*, int*> result(&dummyConstSuccess);
Result<const float*, int*> movedResult(std::move(result));
TestSuccess(&movedResult, &dummyConstSuccess);
}
// Test returning a success Result<const T*, E*>
TEST(ResultBothPointerWithConstResult, ReturningSuccess) {
auto CreateSuccess = []() -> Result<const float*, int*> { return {&dummyConstSuccess}; };
Result<const float*, int*> result = CreateSuccess();
TestSuccess(&result, &dummyConstSuccess);
}
// Result<T, E>
// Test constructing an error Result<T, E>