Unit tests. How to run tests in the main() - c++

I am trying to run a test in the main function, but the error "you cannot overload the main () function"is displayed.
#define CATCH_CONFIG_RUNNER // -- main() создавать нужно --
#include "catch.hpp"
int main(int argc, char* argv[])
{
setlocale(LC_ALL, "Russian");
int result = Catch::Session().run(argc, argv);
system("pause");
return result;
}

You should use Catch in some other way. Something like that worked for me:
#include <iostream> // some standard includes, whatever you need
#define CATCH_CONFIG_MAIN
#include "catch.hpp"
TEST_CASE("My first test") {
// --- test code here ---
}
TEST_CASE("My second test") {
// --- test code here ---
}
Try the framework's tutorial to learn more =)

Related

C++ program not reaching first line of main

This is main.h, I shared with you just in case there would be something wrong here. But I don't think so.
Then, there is main.cpp which is the entry point of my program.
If I generate it with Visual Studio 2017, it will compile and run without errors but it will not print anything on the console.
I can't figure out why.
main.h:
#pragma once
#include <thread>
#include "GabEngine/MainEngine.h"
#include "GraphicInterface/Console.h"
#include "GabEngine/Globals.h"
int m_ScreenWidth = 500, m_ScreenHeight = 500;
GabEngine::Wind m_RootWindow;
GabEngine::MainEngine m_MainEngine(&m_RootWindow);
Globals::NetworkStatus NetStatus;
Networking::MainNetwork m_MainNetwork(&NetStatus);
void TaskConsole();
void TaskNetwork();
main.cpp:
#include "GraphicInterface/main.h"
#include <iostream>
#undef main
void TaskConsole()
{
if (SDL_Init(SDL_INIT_EVERYTHING) != 0)
{
GabEngine::FatalError("Failed to initialize SDL");
}
m_RootWindow.Create("Utryon", m_ScreenWidth, m_ScreenHeight, 2);
m_MainEngine.InitShaders();
m_MainEngine.InitCEGUI("C:/Users/Bob/Documents/Visual Studio 2017/Projects/Utryon/GabEngine/GUI");
m_MainEngine.LoadScheme("UtryonLook.scheme");
m_MainEngine.SetFont("DejaVuSans-10");
GraphicInterface::Console MainConsole(&m_MainEngine, &m_MainNetwork);
MainConsole.InitConsole();
MainConsole.Run();
}
void TaskNetwork()
{
m_MainNetwork.Run();
}
int main(int argc, char** argv)
{
std::cout << "Here 1" << std::endl; //It is supposed to print Here 1
thread ConsoleThread(TaskConsole);
thread NetworkThread(TaskNetwork);
ConsoleThread.join();
NetworkThread.join();
// End of program
return 0;
}

ASSERT: "allArguments.size() == origArgc"

I'm having this error in my Qt Application:
Debug Error!
Program: C:\Qt\Qt5.1.1\5.1.1\msvc2012_64\bin\QtCored.dll
Module: 5.1.1 File: global\qglobal.cpp
Line: 2014
ASSERT: "allArguments.size() == origArgc" in file
kernel\qcoreapplication.cpp, line 2095
#include <QCoreApplication>
#include <QDebug>
#include <QStringList>
int main(int argc, char *argv[])
{
QCoreApplication app(argc,argv);
qDebug()<<"argc:" << argc;
qDebug()<<"arguments:"<<app.arguments().length();
return 0;
}
Why is that so?
The issue was that I was passing arguments with a new line character in it.
After I removed, it worked again.

Error make:*** [unit_test] in googleTest

I have a project named Movies and I run some tests from googletest on it. I included the whole project and started running tests:
#include "gtest/gtest.h"
#include "Counter.h"
#include <iostream>
using namespace std;
TEST(CodeTest, failTest)
{
Counter c;
EXPECT_EQ( 7, c.getValue() );
}
TEST(CodeTest, plusEqualsConstructor)
{
Counter f,g;
f=g+1;
EXPECT_FALSE(f==g);
}
and my main program is:
#include "gtest/gtest.h"
using namespace std;
int main(int argc, char** argv)
{
testing::InitGoogleTest(&argc, argv);
RUN_ALL_TESTS();
return 0;
};
at first it worked as expected and then it gave me the following weird error:
make:*** [unit_test] Error 1
does anyone know what the problem can be? Thank you !!

QList + QVariant + dbus, what difference?

Code bellow. In this variants it doesn't work, it says:
int main(int, char**): mount error msg `Method "FilesystemMount" with signature "bas" on interface "org.freedesktop.UDisks.Device" doesn't exit.
But if I replace "#if 0" with "#if 1" all will works fine.
Can you explain?
#include <cstdio>
#include <cstdlib>
#include <QtCore/QCoreApplication>
#include <QtCore/QStringList>
#include <QtDBus/QDBusMessage>
#include <QtDBus/QDBusPendingReply>
#include <QtDBus/QDBusConnection>
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
if (argc != 2) {
fprintf(stderr, "Usage: %s path/to/device\n", argv[0]);
return EXIT_FAILURE;
}
const QString dev_path(argv[1]);
auto mount_call = QDBusMessage::createMethodCall("org.freedesktop.UDisks", dev_path, "org.freedesktop.UDisks.Device", "FilesystemMount");
#if 0
QList<QVariant> args;//WHY THIS WORKS???
args << QVariant(QString()) << QVariant(QStringList("sync"));
#else
QList<QVariant> args;//AND WHY THIS NOT WORKS???
QVariant filesystem_type(QString());
QVariant opts(QStringList("sync"));
args << filesystem_type << opts;
#endif
mount_call.setArguments(args);
QDBusPendingReply<QVariantMap> mount_res = QDBusConnection::systemBus().call(mount_call);
if (!mount_res.isValid())
fprintf(stderr, "%s: mount error msg `%s'\n", __PRETTY_FUNCTION__, mount_res.error().message().toLocal8Bit().data());
return app.exec();
}
So for me this looks likes:
Container<T> c;
T a;
T b;
c.append(a);
c.append(b);
vs
Container c;
c.append(T());
c.append(T());
but the content of "c" should be the same after end of both control flow?
Ok, I found the reason:
compiler thought that:
QVariant filesystem_type(QString());
is a pointer to function, not a QVariant object;

hypertable example in c++

where i can find an sample code for hypertable or else can any one post an sample for hypertable with c++
If you meant the source code for hypertable
otherwise here is the manual
You can use this HQL tutorial or look at this example
see this:: http://blog.hypertable.com/
and download hypertable project :: http://www.hypertable.org/
#ifndef BOOST_FOREACH
#define BOOST_FOREACH 0
#endif
#include "Common/Compat.h"
#include "Common/System.h"
#include <arpa/inet.h>
#include <iostream>
#include <fstream>
#include "ThriftBroker/Client.h"
#include "ThriftBroker/gen-cpp/HqlService.h"
#include "ThriftBroker/ThriftHelper.h"
#include "ThriftBroker/SerializedCellsReader.h"
using namespace Hypertable;
using namespace Hypertable::ThriftGen;
int main (int argc, char **argv)
{
Thrift::Client *client = new Thrift::Client("localhost", 38080);
if (!client->namespace_exists("/"))
{
delete client;
return 0;
}
Namespace ns = client->namespace_open("/");
HqlResult result;
client->hql_query(result, ns, "select * from foo");
std::cout << result << std::endl;
client->namespace_close(ns);
delete client;
return 0;
}
将其和/opt/hypertable/current/include/ThriftBroker/gen-cpp文件夹下的
Client_constants.cpp、Client_types.cpp、ClientService.cpp、Hql_constants.cpp、Hql_types.cpp、HqlService.cpp一起编译