A有这样的结构(在mongodb c驱动程序的bson.h中定义):
typedef struct
{
uint32_t domain;
uint32_t code;
char message[504];
} bson_error_t;
Run Code Online (Sandbox Code Playgroud)
在Swift中,我有一个指向这个结构的指针,如下所示:
err: UnsafePointer<bson_error_t> = ...
Run Code Online (Sandbox Code Playgroud)
现在无论我做什么,我都无法转换message[504](Swift认为它是(Int8,Int8,Int8,... 504次)的元组)以char*在String.fromCString()中使用它.甚至可以在Swift中做到这一点?作为一个临时解决方案,我在一个单独的.c文件中创建了一个辅助C函数,它接受err *bson_error_t并返回char*,但如果Swift不能单独执行它,这很奇怪.
我正在使用谷歌模拟1.7.0与谷歌测试1.7.0.问题是当我使用NiceMock时,由于意外的模拟函数调用而导致测试失败(根据Google Mock文档,NiceMock应该忽略它).代码如下所示:
// Google Mock test
#include <gtest/gtest.h>
#include <gmock/gmock.h>
using ::testing::Return;
using ::testing::_;
class TestMock {
public:
TestMock() {
ON_CALL(*this, command(_)).WillByDefault(Return("-ERR Not Understood\r\n"));
ON_CALL(*this, command("QUIT")).WillByDefault(Return("+OK Bye\r\n"));
}
MOCK_METHOD1(command, std::string(const std::string &cmd));
};
TEST(Test1, NiceMockIgnoresUnexpectedCalls) {
::testing::NiceMock<TestMock> testMock;
EXPECT_CALL(testMock, command("STAT")).Times(1).WillOnce(Return("+OK 1 2\r\n"));
testMock.command("STAT");
testMock.command("QUIT");
}
Run Code Online (Sandbox Code Playgroud)
但是当我运行测试时它失败并显示以下消息:
[ RUN ] Test1.NiceMockIgnoresUnexpectedCalls
unknown file: Failure
Unexpected mock function call - taking default action specified at:
.../Test1.cpp:13:
Function call: command(@0x7fff5a8d61b0 "QUIT")
Returns: "+OK Bye\r\n"
Google Mock tried the following 1 expectation, but it …Run Code Online (Sandbox Code Playgroud) 我在使用来自xcode 4.6.2的clang ++在mac os x 10.8.3下使用"-std = c ++ 11 -stdlib = libc ++"编译程序时遇到问题.
当我尝试使用std :: mem_fn()或(不赞成)std :: mem_fun_ref()时,我得到链接器错误"找不到符号".相同的代码(使用std :: mem_fun_ref而不是std :: mem_fn)在c ++ 03标准下编译和链接没有任何问题.
如果我在一个对象上调用相同的成员函数而不通过mem_fn或mem_fun_ref引用它,程序将编译并运行没有任何问题.这是一个clang ++问题,一个mac os问题,还是我做错了什么?
代码:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main(int argc, char **arvc)
{
/* The beginning of the function compiles without any errors */
string str = "It's a test)";
if (str.empty())
{
cout << "String is empty!!!" << endl;
}
vector<string> v1;
v1.push_back("str1");
v1.push_back("str2");
v1.push_back("");
v1.push_back("str4"); …Run Code Online (Sandbox Code Playgroud) 我有一个字符串,说var str = "hello, world"和List的Regex模式
val patterns = List(new Regex("hello, (.*)", "substr"), new Regex("hi, (.*)", "substr"))
Run Code Online (Sandbox Code Playgroud)
我如何匹配str这些模式?现在,List我没有使用模式,而是执行以下操作:
val pattern1 = new Regex("hello, (.*)", "substr")
val pattern2 = new Regex("hi, (.*)", "substr")
var someVar = "something"
var someVar2 = "something else"
str match {
case pattern1(substr) => { someVar = substr; someVar2 = "someValue" }
case pattern2(substr) => { someVar = substr; someVar2 = "someOtherValue" }
}
Run Code Online (Sandbox Code Playgroud)
附录:
我忘了提一件重要的事情:实际上有几个模式列表.并且someVar2取决于发生第一个模式匹配的列表而取其值.对我来说,无论是使用嵌套列表List(List(new Regex(...), …
我开发了一个类,它接受implicit engineProvider: ClientSSLEngineProvider一个构造函数参数.当我实例化类时,我的源文件中的任何地方都没有任何隐式定义此类型,但代码编译时没有任何错误.当我使用调试器时,我可以看到这个参数是用一些值初始化的.看起来这个隐式是在其他地方定义的(在其中一个导入中).
如何找到定义它的确切位置?如果重要的话,我正在使用IDEA进行开发.