小编Chr*_*ris的帖子

单元测试在调试模式下成功,但在正常运行时失败

为什么我的单元测试在调试模式下成功但在正常运行时失败?

public class ExecutorServiceTest extends MockitoTestCase{   
  private int numThreads;
  private ExecutorService pool;
  private volatile boolean interruptedBitSet;

  @Override
  public void setUp() {
    numThreads = 5;
    pool = Executors.newFixedThreadPool(numThreads);
  }

class TaskChecksForInterruptedBit implements Callable<String> {
    @Override
    public String call() throws Exception {
      interruptedBitSet = false;
      while (!Thread.currentThread().isInterrupted()) {
      }
      interruptedBitSet = Thread.currentThread().isInterrupted();
      return "blah";
    }
  }

public void testCancelSetsInterruptedBitInCallable() throws Exception {
    interruptedBitSet = false;
    final Future<String> future = 
        pool.submit(new TaskChecksForInterruptedBit());
    final boolean wasJustCancelled = future.cancel(true);
    assertTrue(wasJustCancelled);

    // Give time for the …
Run Code Online (Sandbox Code Playgroud)

java junit multithreading future callable

10
推荐指数
2
解决办法
8275
查看次数

是否可以禁用编译器警告C4503?

以下代码不会抑制任何C4503编译器警告,但它会抑制C4244警告.

#pragma warning(push)
#pragma warning(disable:4503)
#pragma warning(disable:4244)

#include <map>
#include <string>

int main(int argc, char *argv[])
{
    class Field;
    typedef std::map<std::string, Field * > Screen;
    typedef std::map<std::string, Screen> WebApp;
    typedef std::map<std::string, WebApp> WebAppTest;
    typedef std::map<std::string, WebAppTest> Hello;
    Hello MyWAT; // The C4503 error is NOT suppressed

    int a;
    a = 5.0f; // The C4244 error is suppressed
}

#pragma warning(pop)
Run Code Online (Sandbox Code Playgroud)

请明确解释为什么不抑制C4503警告.注意:这可能是由于我如何在第三方库中解决警告C4505中引用的类似原因.

更多相关infornation.

我在Windows 7机器上使用Visual Studio 2008.

c++ warnings pragma suppress-warnings visual-studio

8
推荐指数
1
解决办法
5864
查看次数

隐式vs显式接口

在下面的示例中,使用隐式接口(案例2和3;模板)与使用显式接口(案例1;指向抽象类的指针)的优缺点是什么?

代码不会改变:

class CoolClass
{
public:
  virtual void doSomethingCool() = 0;
  virtual void worthless() = 0;
};

class CoolA : public CoolClass
{
public:
  virtual void doSomethingCool()
  { /* Do cool stuff that an A would do */ }

  virtual void worthless()
  { /* Worthless, but must be implemented */ }
};

class CoolB : public CoolClass
{
public:
  virtual void doSomethingCool()
  { /* Do cool stuff that a B would do */ }

  virtual void worthless()
  { /* Worthless, …
Run Code Online (Sandbox Code Playgroud)

c++ templates interface

7
推荐指数
1
解决办法
1951
查看次数

内存[de]分配成本和潜在的编译器优化(c ++)

内存[de]分配的成本是否明确定义?如果成本取决于所使用的特定编译器,是否有一般的方式实现内存[de]分配,以便我可以合理地假设成本?

编译器是否能够优化以下代码,使得对"new"的调用只进行一次?

char * arr = NULL;
for (size_t i = 0; i < 5000000000; ++i)
{
    arr = new char[100000000]
    ... // Process things here
    delete []arr;
}
Run Code Online (Sandbox Code Playgroud)

c++ memory-management overhead compiler-optimization

6
推荐指数
1
解决办法
1305
查看次数

范围解析运算符在类名中的用途是什么意思

我遇到了这段代码.

class SomeClass::OtherClass : public BaseClass
{
  // stuff in here
}
Run Code Online (Sandbox Code Playgroud)

SomeClass是一个类,所以也许OtherClass是一个存在于SomeClass范围内的类?我从来没有见过这样做过.

那么,这意味着什么?

c++ class scope-resolution

5
推荐指数
1
解决办法
4370
查看次数

如何在调用模拟对象的方法时验证返回值

使用Mockito,有没有办法对一个对象进行spy()并验证一个对象是否被指定的#s次调用给定的#并且它返回这些调用的期望值?

我想做类似以下的事情:

class HatesTwos {
  boolean hates(int val) {
    return val == 2;
  }
}

HatesTwos hater = spy(new HatesTwos());
hater.hates(1);
assertFalse(verify(hater, times(1)).hates(1));

reset(hater);
hater.hates(2);
assertTrue(verify(hater, times(1)).hates(2));
Run Code Online (Sandbox Code Playgroud)

java mocking mockito spy

3
推荐指数
1
解决办法
6111
查看次数

typedef包含模板化类的共享指针

假设我有一些模板类前向声明​​,我想键入一个共享指针.我该怎么做?

template<typename T> class Arg;
typedef std::tr1::shared_ptr<Arg> ArgPtr; // Compiler error
Run Code Online (Sandbox Code Playgroud)

c++ templates class shared-ptr forward-declaration

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

我可以通过Google电子表格将数组传递到Google App Script方法吗?

我可以通过Google电子表格将数组传递到Google App Script方法吗?

假设我有一个App Script函数,它需要一个包含两个元素的列表(注意:这个例子只是一个例子,所以请不要告诉我,如果我只是将每个元素作为一个单独的参数传递,我的问题就会得到解决).如何从Google电子表格单元格调用此功能?

我试过了两个:'= myFunc([1,2])'和'= myFunc((1,2))'并且都给了我一个Parse Error.

javascript spreadsheet google-apps google-sheets google-apps-script

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

直接初始化POD变量不起作用,但复制初始化在将变量推送到矢量时会起作用

为什么以下代码无法编译,而编译成功后的两个示例?我在Windows 7上使用VS 2008.


直接初始化POD(失败):

int pod();
std::vector<int> pods;
//pods.push_back(pod); // This will generate a compiler error
// Compile error: 1>c:\test.hpp(43) : error C2664: 'std::vector<_Ty>::push_back' : cannot convert parameter 1 from 'int (__cdecl *)(void)' to 'const int &'
Run Code Online (Sandbox Code Playgroud)

复制POD的初始化(成功:

int pod = int();
std::vector<int> pods;
pods.push_back(pod); // No error!
Run Code Online (Sandbox Code Playgroud)

c++ initialization copy-initialization

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