本文整理汇总了C++中None函数的典型用法代码示例。如果您正苦于以下问题:C++ None函数的具体用法?C++ None怎么用?C++ None使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了None函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: validateContainerId
Option<Error> validateContainerId(const ContainerID& containerId)
{
const string& id = containerId.value();
// Check common Mesos ID rules.
Option<Error> error = common::validation::validateID(id);
if (error.isSome()) {
return Error(error->message);
}
// Check ContainerID specific rules.
//
// Periods are disallowed because our string representation of
// ContainerID uses periods: <uuid>.<child>.<grandchild>.
// For example: <uuid>.redis.backup
//
// Spaces are disallowed as they can render logs confusing and
// need escaping on terminals when dealing with paths.
auto invalidCharacter = [](char c) {
return c == '.' || c == ' ';
};
if (std::any_of(id.begin(), id.end(), invalidCharacter)) {
return Error("'ContainerID.value' '" + id + "'"
" contains invalid characters");
}
// TODO(bmahler): Print the invalid field nicely within the error
// (e.g. 'parent.parent.parent.value'). For now we only have one
// level of nesting so it's ok.
if (containerId.has_parent()) {
Option<Error> parentError = validateContainerId(containerId.parent());
if (parentError.isSome()) {
return Error("'ContainerID.parent' is invalid: " + parentError->message);
}
}
return None();
}
示例2: TYPED_TEST
// This test verifies that access to the '/flags' endpoint can be authorized
// without authentication if an authorization rule exists that applies to
// anyone. The authorizer will map the absence of a principal to "ANY".
TYPED_TEST(SlaveAuthorizerTest, AuthorizeFlagsEndpointWithoutPrincipal)
{
const string endpoint = "flags";
// Because the authenticators' lifetime is tied to libprocess's lifetime,
// it may already be set by other tests. We have to unset it here to disable
// HTTP authentication.
// TODO(nfnt): Fix this behavior. The authenticator should be unset by
// every test case that sets it, similar to how it's done for the master.
http::authentication::unsetAuthenticator(
slave::DEFAULT_HTTP_AUTHENTICATION_REALM);
// Setup ACLs so that any principal can access the '/flags' endpoint.
ACLs acls;
acls.set_permissive(false);
mesos::ACL::GetEndpoint* acl = acls.add_get_endpoints();
acl->mutable_principals()->set_type(mesos::ACL::Entity::ANY);
acl->mutable_paths()->add_values("/" + endpoint);
slave::Flags agentFlags = this->CreateSlaveFlags();
agentFlags.acls = acls;
agentFlags.authenticate_http = false;
agentFlags.http_credentials = None();
// Create an `Authorizer` with the ACLs.
Try<Authorizer*> create = TypeParam::create(parameterize(acls));
ASSERT_SOME(create);
Owned<Authorizer> authorizer(create.get());
StandaloneMasterDetector detector;
Try<Owned<cluster::Slave>> agent = this->StartSlave(
&detector, authorizer.get(), agentFlags);
ASSERT_SOME(agent);
Future<Response> response = http::get(agent.get()->pid, endpoint);
AWAIT_EXPECT_RESPONSE_STATUS_EQ(OK().status, response)
<< response.get().body;
}
示例3: GetTreeObject
void CNamingTreeCtrl::OnCopy()
{
// TODO: Add your command handler code here
CNamingObject* pObject = GetTreeObject();
try
{
CString IOR = m_pORB->object_to_string(pObject->Object());
// Copy to the clipboard by using the CEdit control. This is easier
// that doing it the right way
CEdit Temp;
CRect None(0,0, 1, 1);
Temp.Create(0, None, this, 0);
Temp.SetWindowText(IOR);
Temp.SetSel(0, IOR.GetLength());
Temp.Copy();
Temp.PostMessage(WM_CLOSE);
}
catch(CORBA::Exception& ex)
{
MessageBox(ACE_TEXT_CHAR_TO_TCHAR (ex._rep_id()), ACE_TEXT ("CORBA::Exception"));
}
}
示例4: TEST_F
// Tests the archive APIs for a simple file.
TEST_F(TarTest, File)
{
// Create a test file.
const Path testFile("testfile");
ASSERT_SOME(createTestFile(testFile));
// Archive the test file.
const Path outputTarFile("test.tar");
AWAIT_ASSERT_READY(command::tar(testFile, outputTarFile, None()));
ASSERT_TRUE(os::exists(outputTarFile));
// Remove the test file to make sure untar process creates new test file.
ASSERT_SOME(os::rm(testFile));
ASSERT_FALSE(os::exists(testFile));
// Untar the tarball and verify that the original file is created.
AWAIT_ASSERT_READY(command::untar(outputTarFile));
ASSERT_TRUE(os::exists(testFile));
// Verify that the content is same as original file.
EXPECT_SOME_EQ("test", os::read(testFile));
}
示例5: construct
namespace uri {
/**
* Construct an URI with the given parameters. No validation will be
* performed in this function.
*/
URI construct(
const std::string& scheme,
const std::string& path = "",
const Option<std::string>& host = None(),
const Option<int>& port = None(),
const Option<std::string>& query = None(),
const Option<std::string>& fragment = None(),
const Option<std::string>& user = None(),
const Option<std::string>& password = None());
} // namespace uri {
示例6: TEST_P
// Tests that an agent endpoint handler forms
// correct queries against the authorizer.
TEST_P(SlaveEndpointTest, AuthorizedRequest)
{
const string endpoint = GetParam();
StandaloneMasterDetector detector;
MockAuthorizer mockAuthorizer;
Try<Owned<cluster::Slave>> agent = StartSlave(&detector, &mockAuthorizer);
ASSERT_SOME(agent);
Future<authorization::Request> request;
EXPECT_CALL(mockAuthorizer, authorized(_))
.WillOnce(DoAll(FutureArg<0>(&request),
Return(true)));
Future<Response> response = http::get(
agent.get()->pid,
endpoint,
None(),
createBasicAuthHeaders(DEFAULT_CREDENTIAL));
AWAIT_READY(request);
const string principal = DEFAULT_CREDENTIAL.principal();
EXPECT_EQ(principal, request.get().subject().value());
// TODO(bbannier): Once agent endpoint handlers use more than just
// `GET_ENDPOINT_WITH_PATH` we should factor out the request method
// and expected authorization action and parameterize
// `SlaveEndpointTest` on that as well in addition to the endpoint.
EXPECT_EQ(authorization::GET_ENDPOINT_WITH_PATH, request.get().action());
EXPECT_EQ("/" + endpoint, request.get().object().value());
AWAIT_EXPECT_RESPONSE_STATUS_EQ(OK().status, response)
<< response.get().body;
}
示例7: TEST_F
TEST_F(ProtobufIOTest, Append)
{
const string file = ".protobuf_io_test_append";
const size_t writes = 10;
for (size_t i = 0; i < writes; i++) {
FrameworkID frameworkId;
frameworkId.set_value(stringify(i));
Try<Nothing> result = ::protobuf::append(file, frameworkId);
ASSERT_SOME(result);
}
Try<int_fd> fd = os::open(
file,
O_CREAT | O_RDONLY | O_CLOEXEC,
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
ASSERT_SOME(fd);
Result<FrameworkID> read = None();
size_t reads = 0;
while (true) {
read = ::protobuf::read<FrameworkID>(fd.get());
if (!read.isSome()) {
break;
}
EXPECT_EQ(read->value(), stringify(reads++));
}
// Ensure we've hit the end of the file without reading a partial
// protobuf.
ASSERT_TRUE(read.isNone());
ASSERT_EQ(writes, reads);
os::close(fd.get());
}
示例8: get
// Returns the netlink link object associated with a given link by its
// interface index. Returns None if the link is not found.
inline Result<Netlink<struct rtnl_link>> get(int index)
{
Try<Netlink<struct nl_sock>> socket = routing::socket();
if (socket.isError()) {
return Error(socket.error());
}
// Dump all the netlink link objects from kernel. Note that the flag
// AF_UNSPEC means all available families.
struct nl_cache* c = NULL;
int error = rtnl_link_alloc_cache(socket.get().get(), AF_UNSPEC, &c);
if (error != 0) {
return Error(nl_geterror(error));
}
Netlink<struct nl_cache> cache(c);
struct rtnl_link* l = rtnl_link_get(cache.get(), index);
if (l == NULL) {
return None();
}
return Netlink<struct rtnl_link>(l);
}
示例9: ping
// Launch 'ping' using the given capabilities and user.
Try<Subprocess> ping(
const Set<Capability>& capabilities,
const Option<string>& user = None())
{
CapabilitiesTestHelper helper;
helper.flags.user = user;
helper.flags.capabilities = capabilities::convert(capabilities);
vector<string> argv = {
"test-helper",
CapabilitiesTestHelper::NAME
};
return subprocess(
getTestHelperPath("test-helper"),
argv,
Subprocess::FD(STDIN_FILENO),
Subprocess::FD(STDOUT_FILENO),
Subprocess::FD(STDERR_FILENO),
NO_SETSID,
&helper.flags);
}
示例10: createTestFile
Try<Nothing> createTestFile(
const Path& file,
const Option<Path>& directory = None())
{
const Path testFile(
directory.isSome() ?
path::join(directory.get(), file.value): file);
const string& testFileDir = testFile.dirname();
if (!os::exists(testFileDir)) {
Try<Nothing> mkdir = os::mkdir(testFileDir, true);
if (mkdir.isError()) {
return Error("Failed to create test directory: " + mkdir.error());
}
}
Try<Nothing> write = os::write(testFile, "test");
if (write.isError()) {
return Error("Failed to create to test file: " + write.error());
}
return Nothing();
}
示例11: main
int main(int argc, char** argv)
{
#ifdef __WINDOWS__
// Initialize the Windows socket stack.
process::Winsock winsock;
#endif
// Initialize Google Mock/Test.
testing::InitGoogleMock(&argc, argv);
// Initialize libprocess.
process::initialize(None(), process::DEFAULT_HTTP_AUTHENTICATION_REALM);
// NOTE: Windows does not support signal semantics required for these
// handlers to be useful.
#ifndef __WINDOWS__
// Install GLOG's signal handler.
google::InstallFailureSignalHandler();
// We reset the GLOG's signal handler for SIGTERM because
// 'SubprocessTest.Status' sends SIGTERM to a subprocess which
// results in a stack trace otherwise.
os::signals::reset(SIGTERM);
#endif // __WINDOWS__
// Add the libprocess test event listeners.
::testing::TestEventListeners& listeners =
::testing::UnitTest::GetInstance()->listeners();
listeners.Append(process::ClockTestEventListener::instance());
listeners.Append(process::FilterTestEventListener::instance());
int result = RUN_ALL_TESTS();
process::finalize();
return result;
}
示例12: TEST_F
// Test that the environment decorator hook adds a new environment
// variable to the executor runtime.
// Test hook adds a new environment variable "FOO" to the executor
// with a value "bar". We validate the hook by verifying the value
// of this environment variable.
TEST_F(HookTest, VerifySlaveExecutorEnvironmentDecorator)
{
const string& directory = os::getcwd(); // We're inside a temporary sandbox.
Fetcher fetcher;
Try<MesosContainerizer*> containerizer =
MesosContainerizer::create(CreateSlaveFlags(), false, &fetcher);
ASSERT_SOME(containerizer);
ContainerID containerId;
containerId.set_value("test_container");
// Test hook adds a new environment variable "FOO" to the executor
// with a value "bar". A '0' (success) exit status for the following
// command validates the hook.
process::Future<bool> launch = containerizer.get()->launch(
containerId,
CREATE_EXECUTOR_INFO("executor", "test $FOO = 'bar'"),
directory,
None(),
SlaveID(),
process::PID<Slave>(),
false);
AWAIT_READY(launch);
ASSERT_TRUE(launch.get());
// Wait on the container.
process::Future<containerizer::Termination> wait =
containerizer.get()->wait(containerId);
AWAIT_READY(wait);
// Check the executor exited correctly.
EXPECT_TRUE(wait.get().has_status());
EXPECT_EQ(0, wait.get().status());
delete containerizer.get();
}
示例13: decode
std::deque<http::Response*> decode(const char* data, size_t length)
{
size_t parsed = http_parser_execute(&parser, &settings, data, length);
if (parsed != length) {
// TODO(bmahler): joyent/http-parser exposes error reasons.
failure = true;
// If we're still writing the body, fail the writer!
if (writer.isSome()) {
http::Pipe::Writer writer_ = writer.get(); // Remove const.
writer_.fail("failed to decode body");
writer = None();
}
}
if (!responses.empty()) {
std::deque<http::Response*> result = responses;
responses.clear();
return result;
}
return std::deque<http::Response*>();
}
示例14: OK
OK(const JSON::Value& value, const Option<std::string>& jsonp = None())
{
type = BODY;
status = "200 OK";
std::ostringstream out;
if (jsonp.isSome()) {
out << jsonp.get() << "(";
}
out << value;
if (jsonp.isSome()) {
out << ");";
headers["Content-Type"] = "text/javascript";
} else {
headers["Content-Type"] = "application/json";
}
headers["Content-Length"] = stringify(out.str().size());
body = out.str().data();
}
示例15: HELP
const std::string Logging::TOGGLE_HELP()
{
return HELP(
TLDR(
"Sets the logging verbosity level for a specified duration."),
DESCRIPTION(
"The libprocess library uses [glog][glog] for logging. The library",
"only uses verbose logging which means nothing will be output unless",
"the verbosity level is set (by default it's 0, libprocess uses levels"
" 1, 2, and 3).",
"",
"**NOTE:** If your application uses glog this will also affect",
"your verbose logging.",
"",
"Query parameters:",
"",
"> level=VALUE Verbosity level (e.g., 1, 2, 3)",
"> duration=VALUE Duration to keep verbosity level",
"> toggled (e.g., 10secs, 15mins, etc.)"),
AUTHENTICATION(true),
None(),
REFERENCES(
"[glog]: https://code.google.com/p/google-glog"));
}