小编use*_*541的帖子

Gmock设置参数

在GMock测试方法,我需要设置了参数变量的地址,这样的输出参数dequeue(),这是data指向变量ch:

MOCK_METHOD1(dequeue, void(void* data));

char ch = 'm';
void* a = (void*)&ch;

EXPECT_CALL(FQO, dequeue(_))
    .WillOnce(/*here I need to set argument to a*/);
Run Code Online (Sandbox Code Playgroud)

我试图找出副作用,但一直出错.

c++ gmock

2
推荐指数
1
解决办法
6075
查看次数

将部分字节数组转换为uint16的最简单方法

如果我是字节数组:

byte_array := []byte("klm,\x15\xf1\n")
Run Code Online (Sandbox Code Playgroud)

我想以LittleEndian顺序将字节\ x15和\ xf1添加到uint16.这样做最简单的方法是什么?

尝试以下方法:

var new_uint uint16
bff := bytes.newRead(byte_array[4:5])
err = binary.Read(buff, binary.LittleEndian, &new_uint)
Run Code Online (Sandbox Code Playgroud)

但我一无所获,这是相对复杂的,有更简单的方法吗?

谢谢...

go

2
推荐指数
1
解决办法
2163
查看次数

将sha256sum的结果读入bash变量

对于sha256sum的以下执行和结果

~/HydroGuardFW/hw_1_5/Debug$ sha256sum debug_2.0.5.hex
34c977f0df3e90f9a4b36da3cd39fdccf3cd1123c563894b3a3378770a19fc6d      debug_2.0.5.hex
Run Code Online (Sandbox Code Playgroud)

输出将分为两部分,即sha256和计算出sha256总和的文件名的回显。如何将输出的第一部分(即sha256)捕获到变量中,以便可以使用bash脚本将其放置到文件中。

bash

2
推荐指数
1
解决办法
2501
查看次数

C++中指向self的成员变量指针

当我尝试编译此代码时,为什么g ++报告错误?

class A {
  private:
    static A* Aptr[5];
  public:
    static int A_count;
    A() {
        Aptr[A_count] = this;
    }
};

int A::A_count = 0;

int main() {
    A a_;
    A b_;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

/tmp/ccrp4BGg.o: In function `A::A()':
try.cpp:(.text._ZN1AC2Ev[_ZN1AC5Ev]+0x18): undefined reference to `A::Aptr'
collect2: error: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)

c++ static-members

0
推荐指数
1
解决办法
1079
查看次数

View exit code of a program (After the program exited)

Lets say a program that outputs a zero in case of success, or 1 in case of failure, like this:

main () {
    if (task_success())
        return 0;
    else
        return 1;
}
Run Code Online (Sandbox Code Playgroud)

Similar with Python, if you execute exit(0) or exit(1) to indicate the result of running a script. How do you know what the program outputs when you run it in shell. I tried this:

./myprog 2> out
Run Code Online (Sandbox Code Playgroud)

but I do not get the result in the file.

linux shell

0
推荐指数
1
解决办法
1998
查看次数

标签 统计

c++ ×2

bash ×1

gmock ×1

go ×1

linux ×1

shell ×1

static-members ×1