小编baz*_*rek的帖子

如何在Visual Studio 2015上使用NuGet Package Manager安装NUnit for C#?

我有Visual Studio 2015.我想用NuGet Package Manager为C#项目添加NUnit的测试,我希望有可能在VS和VS中运行测试.

  1. 首先我创建新的C#项目:文件 - >新建 - >项目 - >>已安装 - >模板 - > Visual C# - >>控制台应用程序 - >>确定

  2. 然后我安装NUnit:工具 - > NuGet包管理器 - >管理解决方案的NuGet包...然后我安装包:

    • NUnit的
    • NUnit.Runner
    • NUnitTestAdapter

在输出中我看到:

Successfully installed 'NUnit 3.0.0-beta-4' to Tmp.
Successfully installed 'NUnit.Runners 2.6.4' to Tmp.
Successfully installed 'NUnitTestAdapter 2.0.0' to Tmp.
Run Code Online (Sandbox Code Playgroud)
  1. 我要做的下一步是添加带有代码的新类:右键单击项目 - >添加 - >类 - >> Visual C#Items - >类名Tests.cs - >添加

然后我使用下面的代码:

namespace NUnit.Tests
{
    using System;
    using NUnit.Framework;

    [TestFixture]
    public class Tests
    {
        [Test]
        public void t1() …
Run Code Online (Sandbox Code Playgroud)

c# nunit nuget-package visual-studio-2015

11
推荐指数
2
解决办法
2万
查看次数

C++中的attribute-list中的省略号应该用于什么?

C++参考中,我发现了有关C++中允许的属性语法的信息,它是:

[[attribute-list]]
[[ using attribute-namespace : attribute-list ]]
Run Code Online (Sandbox Code Playgroud)

"其中attribute-list是一个逗号分隔的零个或多个属性的序列(可能以省略号结尾...表示包扩展)"

我试过用它,但我发现之间没有区别:

[[deprecated]] void f() 
{
}
Run Code Online (Sandbox Code Playgroud)

[[deprecated...]] void f() 
{
}
Run Code Online (Sandbox Code Playgroud)

在这两种情况下输出都是相同的.

c++ attributes ellipsis

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

C++ boost :: program_options读取与getopt_long兼容的参数

我正在开发一个现有程序的更新.我正在用boost :: program_options替换Posix的getopt_long().但是我的工作并没有像我应该的那样工作:我希望阅读如下的论点:

-server=www.example.com
-c config.txt
Run Code Online (Sandbox Code Playgroud)

我尝试了boost :: program_options :: command_line_style的许多可能性,但是我找不到能够使行为等于getopt_long的组合.

我发现了这个论点:

-server=www.example.com
Run Code Online (Sandbox Code Playgroud)

我需要旗帜:

command_line_style::allow_long_disguise | command_line_style::long_allow_adjacent
Run Code Online (Sandbox Code Playgroud)

但我有建立标志的问题:

-c config.txt
Run Code Online (Sandbox Code Playgroud)

我找到了旗帜:

command_line_style::allow_short | command_line_style::allow_dash_for_short | command_line_style::short_allow_next
Run Code Online (Sandbox Code Playgroud)

给我几乎我想要的东西.几乎是因为:

ProgramOptionsParserTest.cpp:107: Failure
Value of: params.config
  Actual: " config.txt"
Expected: expectedParams.config
Which is: "config.txt"
Run Code Online (Sandbox Code Playgroud)

所以在使用boost :: algorithm :: trim()后,它将是我想要的.

所以我的问题是:是否可以使用boost :: program_options处理像-c config.txt这样的参数但没有boost :: algorithm :: trim()?

编辑 我注意到上面的标志不适用于未注册的参数.我有注册选项:

  programOptionsDescription.add_options()
      ("help,h", "display help message")
      ("config,c", value<std::string>(), "use configfile")
      ("server,s", value<std::string>(), "server")
      ("ipport,p", value<uint16_t>(), "server port");
Run Code Online (Sandbox Code Playgroud)

但是当我使用未注册的选项时(是的,我有basic_command_line_parser :: allow_unregistered()):

-calibration=something
Run Code Online (Sandbox Code Playgroud)

我知道了:

the argument ('alibration=something') for …
Run Code Online (Sandbox Code Playgroud)

c++ boost getopt-long boost-program-options

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

C++使用带字符串的标准算法,带有isdigit的count_if,函数转换

我想以最短的代码方式计算字符串中的所有数字.我试过这样的方式:

#include <string>
#include <algorithm>

unsigned countNumbers(const std::string s) {
    return count_if(s.begin(), s.end(), isdigit);
}
Run Code Online (Sandbox Code Playgroud)

错误信息是:

a.cc: In function ‘unsigned int countNumbers(std::string)’:
a.cc:5:45: error: no matching function for call to ‘count_if(std::basic_string<char>::const_iterator, std::basic_string<char>::const_iterator, <unresolved overloaded function type>)’
a.cc:5:45: note: candidate is:
/usr/include/c++/4.6/bits/stl_algo.h:4607:5: note: template<class _IIter, class _Predicate> typename std::iterator_traits<_InputIterator>::difference_type std::count_if(_IIter, _IIter, _Predicate)
Run Code Online (Sandbox Code Playgroud)

我知道count_if()想要的函数如下:bool(*f)(char); 作为第三个参数,所以我试图强制转换函数:

unsigned countNumbers(const std::string s) {
    return count_if(s.begin(), s.end(), reinterpret_cast<bool (*)( char )>(isdigit));
}
Run Code Online (Sandbox Code Playgroud)

错误信息是:

a.cc: In function ‘unsigned int countNumbers(std::string)’:
a.cc:5:80: error: overloaded function with no contextual …
Run Code Online (Sandbox Code Playgroud)

c++ string algorithm casting function

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

Python,为什么在使用TCP套接字时出现错误10035(在服务器上)和10053(在客户端上)?

差不多2天我仍然有同样的问题 - 客户端和服务器"对话",但我不知道为什么在通信过程中突然出现问题.我尝试了很多东西,不幸的是仍然是同样的问题.

我在Windows 7上使用python 2.7.5.

我的代码: cs_common.py

import socket
import os
import sys
import errno
from time import sleep


HOST = 'localhost'
MY_IP = socket.gethostbyname(socket.gethostname())
PORT = 50007
timeout_in_seconds = 2

def createSocket4server(host, port):
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.bind((host, port))
    s.listen(4)
    return s

def createSocket4Client(host, port, timeout_in_seconds=3):
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

    s.connect( (host, port) )
    print 'connected to %s port %s' % (host, port)
    return s

sent = 0
def sendToSocket(socket_, data): # to debug
    global sent
    print sent, …
Run Code Online (Sandbox Code Playgroud)

python sockets client tcp

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

何时在C中使用可变长度数组,但是在动态分配时?

我在C99中找到了可变长度数组,但看起来它的行为与malloc + free几乎相同.

我找到的实际差异:

  1. 太大的阵列处理:

    unsigned size = 4000000000;
    int* ptr = malloc(size); // ptr is 0, program doesn't crash
    int array[size]; // segmentation fault, program crashes
    
    Run Code Online (Sandbox Code Playgroud)
  2. 内存泄漏:只能在动态数组分配中使用:

    int* ptr = malloc(size);
    ...
    if(...)
        return;
    ...
    free(ptr);
    
    Run Code Online (Sandbox Code Playgroud)
  3. 对象的生命和从函数返回的可能性:动态分配的数组生命直到内存释放,并且可以从分配内存的函数返回.

  4. 调整大小:仅使用指向已分配内存的指针调整大小.

我的问题是:

  • 有什么更多的差异(我对实用建议感兴趣)?
  • 程序员可以使用两种具有可变长度的数组的方式有什么问题?
  • 何时选择VLA但是在动态阵列分配时?
  • 什么是更快:VLA或malloc +免费?

c arrays malloc free c99

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

如何在Visual Studio 2013中的C++项目中编译和链接谷歌测试,但是NuGet包管理器安装了Gtest?

我在Windows 7上安装了Microsoft Visual Studio 2013社区版.我想以比下载标题和二进制文件或自行编译更新的方式为C++安装gtest和gmock.

我找到了Tools> Nuget Package Manager> Manage Nugets Packages for Solution我选择了Online,然后输入gtest.从搜索结果中我发现了Google Test,所以我已经为我当前的项目安装了它.安装后,下面的代码编译:

#include <iostream>
#include <gtest\gtest.h>

using namespace std;
using namespace ::testing;

int factorian(int n)
{
    if (n == 0 || n == 1)
        return 1;
    else
        return n*factorian(n - 1);
}

TEST(factorianTest, simpleTest)
{
    ASSERT_EQ(1, factorian(0));
    ASSERT_EQ(1, factorian(1));
    ASSERT_EQ(2, factorian(2));
}

int main(int argc, char* argv[])
{
    InitGoogleTest(&argc, argv);
    return RUN_ALL_TESTS();
}
Run Code Online (Sandbox Code Playgroud)

但它没有链接:

错误1错误LNK2019:未解析的外部符号"bool __cdecl testing :: internal :: IsTrue(bool)"(?IsTrue @ internal @ testing @@ YA_N_N …

c++ linker googletest visual-studio nuget

5
推荐指数
2
解决办法
3906
查看次数

只有在测试失败时,c ++ gtest才会在测试结束时输出其他信息

我想做这样的事情:

TEST(MyTestFixture, printAfterExpectationFailure)
{
  const string request("bring me tea");

  const string&& response = sendRequestAndGetResponse(request);

  checkResponseWithExpectarions1(response);
  checkResponseWithExpectarions2(response);
  checkResponseWithExpectarions3(response);
  checkResponseWithExpectarions4(response);

  if (anyOfExpectsFailed())
      cout << "Request: " << request << "\nresponse: " << response << endl;
}

TEST(MyTestFixture, printAfterAssertionFailure)
{
  const string request("bring me tea");

  const string&& response = sendRequestAndGetResponse(request);

  doWhenFailure([&request, &response]()
  {
      cout << "Request: " << request << "\nresponse: " << response << endl;
  });

  checkResponseWithAssertion1(response);
  checkResponseWithAssertion2(response);
  checkResponseWithAssertion3(response);
  checkResponseWithAssertion4(response);
}
Run Code Online (Sandbox Code Playgroud)

我仅在期望/断言失败时才打印一些其他信息。

我知道我可以做这样的事情:

#define MY_ASSERT_EQ(lhr, rhs, message) if(lhs != rhs) ASSERT_EQ(lhs, rhs) …
Run Code Online (Sandbox Code Playgroud)

c++ assert expectations googletest assertions

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

如何打印specyfic字符串而不使用双引号或单引号?

我的任务是显示指定的文本,例如"dummy123".但问题是我不能既不使用"也不能"做那样的事情.正如我所知,在Java中没有像预处理器那样

#define W(x) #x;
Run Code Online (Sandbox Code Playgroud)

如何使用没有引号的代码:

public class A
{
    public static void main(String[] args)
    {
       System.out.println("dummy123");
    }
}
Run Code Online (Sandbox Code Playgroud)

java

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

vcpkg安装包时编译失败如何编辑包文件?

我正在为一些下载依赖项的项目安装依赖项vcpkg(该项目是 Hyperledger Iroha,但这并不重要)。不幸的是,当使用我的编译器(g++ 12.1.0)编译依赖项时,其中一个包(abseil)无法编译。

\n

它不编译的原因很容易在代码中修复 - 只需更改一行。

\n

该线由cmake

\n
CMake Error at scripts/cmake/vcpkg_execute_build_process.cmake:146 (message):\n    Command failed: /usr/bin/cmake --build . --config Debug --target install -- -v -j13\n    Working Directory: /home/agh/Pulpit/blockchain/internship2022/iroha/vcpkg-build/buildtrees/abseil/x64-linux-dbg\n    See logs for more information:\n      /home/agh/Pulpit/blockchain/internship2022/iroha/vcpkg-build/buildtrees/abseil/install-x64-linux-dbg-out.log\n
Run Code Online (Sandbox Code Playgroud)\n

错误是:

\n
/home/agh/Pulpit/blockchain/internship2022/iroha/vcpkg-build/buildtrees/abseil/src/ca9688e9f6-e4cda1d679.clean/absl/debugging/failure_signal_handler.cc:139:32: error: no matching function for call to \xe2\x80\x98max(long int, int)\xe2\x80\x99\n  139 |   size_t stack_size = (std::max(SIGSTKSZ, 65536) + page_mask) & ~page_mask;\n      |                        ~~~~~~~~^~~~~~~~~~~~~~~~~\nIn file included from /usr/include/c++/12.1.0/algorithm:60,\n
Run Code Online (Sandbox Code Playgroud)\n

原因很容易修复 - 我只需要更改一行即可解决此问题。\n不幸的是,当我更改代码行并重新运行后:

\n
vcpkg install abseil\n …
Run Code Online (Sandbox Code Playgroud)

c++ dependencies package-managers cmake vcpkg

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