-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Function example to use string args
- Loading branch information
Showing
3 changed files
with
18 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,15 +5,6 @@ | |
|
||
static const std::string APP_ID = "cpp-tester-uliix"; | ||
|
||
// This test is currently commented out because the SDK has removed the | ||
// exposed Core headers that gave it access to a BSON library. | ||
// See PR https://github.com/realm/realm-cpp/pull/123/ | ||
// Per Lee, a separate project will create a C++ SDK BSON library, but in | ||
// the meantime, I'll need to use some other library to make this test work. | ||
// I need to figure out how to create BSON strings in C++ and pass them | ||
// instead of using realm::bson::Bson for the params. | ||
// TODO: Figure out what library to use and how to make this test/example work. | ||
#if 0 | ||
TEST_CASE("call a function", "[realm][sync]") { | ||
// :snippet-start: call-a-function | ||
// Connect to an App Services App and authenticate a user | ||
|
@@ -25,24 +16,21 @@ TEST_CASE("call a function", "[realm][sync]") { | |
auto user = app.login(realm::App::credentials::anonymous()).get(); | ||
auto sync_config = user.flexible_sync_configuration(); | ||
|
||
// If a function takes arguments, pass them as BSON | ||
auto arg1 = realm::bson::Bson("john.smith"); | ||
auto arg2 = realm::bson::Bson("@companyemail.com"); | ||
// If the function takes arguments, pass them as a string array. | ||
// Any quotes within the array must be escaped. | ||
auto argArray = "[\"john.smith\", \"@companyemail.com\"]"; | ||
|
||
// Call an App Services function as the logged-in user | ||
auto result = user.call_function("concatenate", {arg1, arg2}).get(); | ||
auto result = user.call_function("concatenate", argArray).get(); | ||
|
||
// Verify that the result has a value | ||
CHECK(result); | ||
auto bsonResult = result.value(); | ||
auto functionResult = result.value(); | ||
|
||
// Translate the BSON result back to a string | ||
auto resultString = std::string(bsonResult); | ||
// Prints "Calling the concatenate function returned | ||
// [email protected]." | ||
std::cout << "Calling the concatenate function returned " << resultString | ||
// "[email protected]"." | ||
std::cout << "Calling the concatenate function returned " << functionResult | ||
<< ".\n"; | ||
// :snippet-end: | ||
REQUIRE(resultString == "[email protected]"); | ||
REQUIRE(functionResult == "\"[email protected]\""); | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,20 +5,18 @@ auto app = realm::App(appConfig); | |
auto user = app.login(realm::App::credentials::anonymous()).get(); | ||
auto sync_config = user.flexible_sync_configuration(); | ||
|
||
// If a function takes arguments, pass them as BSON | ||
auto arg1 = realm::bson::Bson("john.smith"); | ||
auto arg2 = realm::bson::Bson("@companyemail.com"); | ||
// If the function takes arguments, pass them as a string array. | ||
// Any quotes within the array must be escaped. | ||
auto argArray = "[\"john.smith\", \"@companyemail.com\"]"; | ||
|
||
// Call an App Services function as the logged-in user | ||
auto result = user.call_function("concatenate", {arg1, arg2}).get(); | ||
auto result = user.call_function("concatenate", argArray).get(); | ||
|
||
// Verify that the result has a value | ||
CHECK(result); | ||
auto bsonResult = result.value(); | ||
auto functionResult = result.value(); | ||
|
||
// Translate the BSON result back to a string | ||
auto resultString = std::string(bsonResult); | ||
// Prints "Calling the concatenate function returned | ||
// [email protected]." | ||
std::cout << "Calling the concatenate function returned " << resultString | ||
// "[email protected]"." | ||
std::cout << "Calling the concatenate function returned " << functionResult | ||
<< ".\n"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters