Visual C++ if statement. The breakpoint will not currently be hit - c++

I'm using Visual Studio 2013, programming in C++ and have a base class with the following attribute:
ref class AI
{
...
protected:
/// <summary>
/// Exit found flag. False if exit is yet to be found, true if it already was.
/// </summary>
bool exitFound;
...
}
Within the derived class I have the following code:
void AI_II::analyze(void)
{
...
this->exitFound = true;
if (this->exitFound)
{
if (this->distFront->lastTile == EXIT){...}
else if (this->distDown->lastTile == EXIT){...}
else if (this->distBack->lastTile == EXIT){...}
else if (this->distUp->lastTile == EXIT){...}
}
...
}
And I don't know how, but when running or debugging, the if (this->exitFound) statement is always skipped. When debugging I get the "The breakpoint will not currently be hit..." message.
I already tried to clean the solution, but no success so far. Anyone can help me find what is wrong?

Select in Visual Studio [Properties] - [Build] tab and check [Define DEBUG constant] and [Define TRACE constant] are checked. Also check [Debug Info] is set to [full] in [Advanced] tab.

Related

If statement not going to else statement in Katalon Studio for Android

I am using Katalon for Android Testing. I want it to click ImageView3 if it is present. If not, it will click ImageView2 (which makes ImageView3 appear later).
I have tried verifyElementVisible and verifyElementNotVisible. Also tried adding the if statement as 'if (Mobile.verifyElementVisible(findTestObject('Objects/android.widget.ImageView3'), 0) == true)' but this produced the same error.
Mobile.tap(findTestObject('Objects/android.widget.ImageView1'), 0)
if (Mobile.verifyElementVisible(findTestObject('Objects/android.widget.ImageView3'), 0))
{
Mobile.verifyElementVisible(findTestObject('Objects/android.widget.ImageView3'), 0)
Mobile.tap(findTestObject('Objects/android.widget.ImageView3'), 0)
Mobile.closeApplication()
} else
{
Mobile.tap(findTestObject('Objects/android.widget.ImageView2'), 30)
Mobile.verifyElementVisible(findTestObject('Objects/android.widget.ImageView3'), 0)
Mobile.tap(findTestObject('Objects/android.widget.ImageView3'), 0)
Mobile.closeApplication()
}
The error in the log is showing the following:
Reason: com.kms.katalon.core.exception.StepFailedException: Element 'Object Repository/Objects/android.widget.ImageView3' not found at com.kms.katalon.core.keyword.internal.KeywordMain.stepFailed(KeywordMain.groovy:48)
As ImageView3 was not found, I would expect it to jump to the else statement. Any suggestion why this is not happening?
The FailureHandling was not set. It would throw an error as this was not set.
Added FailureHandling.OPTIONAL to the if statement
if (Mobile.verifyElementVisible(findTestObject('Objects/android.widget.ImageView3'), 0, FailureHandling.OPTIONAL))

QString functions giving incorrect results on CentOS

I am using C++ Qt Library and following code is working perfectly on Windows but not working on CentOS :
if(line.startsWith("[", Qt::CaseInsensitive))
{
int index = line.indexOf(']', 0, Qt::CaseInsensitive);
QString subLine = line.mid(index+1);
subLine = subLine.trimmed();
tokenList = subLine.split("\t");
}
else
{
tokenList = line.split("\t");
}
I have a line [ x.x.x.x ] something ../dir/file.extension and I want to ignore the [x.x.x.x] part while breaking line into tokens. I am using VC9 on windows to debug and its working fine.
Edit: i have removed mid() and used right() still same problem persists, working on windows but not on CentOS.
Edit: after debugging on linux using QMessageBox i have concluded that control is never going inside if block, i tried using if(line.data()[0] == '[') but same results.
Your code can be simplified.
line.remove(QRegExp("\\[\\s+\\d+\\.\\d+\\.\\d+\\.\\d+\\s+\\]"));
tokenList = line.split("\t");

Glass Throwing Error

I have some questions regarding my block of code. I've tried running it in Netbeans and it doesn't seem to like this block of code on Google Glass. I compiled it using Eclipse and it seems to compile correctly as well.
package com.openglassquartz.helloglass;
import java.io.IOException;
import java.net.URL;
import java.util.Scanner;
public class OnlineRetrieval {
boolean activeGame;
public boolean checkGame() { //Method for which to check if there is a current game going on.
try {
URL url = new URL("http://danielchan.me/league/active.txt");
Scanner s = new Scanner(url.openStream()); //All errors point to this line of code??
int temporary_Reading = s.nextInt();
if(temporary_Reading == 1) {
return activeGame = true;
} else {
return activeGame = false;
}
} catch(IOException ex) {
ex.printStackTrace();
}
return activeGame;
}
}
From the LaunchService Class.
OnlineRetrieval OR = new OnlineRetrieval();
boolean temp_Check = OR.checkGame();
01-14 16:38:32.187: E/AndroidRuntime(18639): at com.openglassquartz.helloglass.OnlineRetrieval.checkGame(OnlineRetrieval.java:20)
01-14 16:38:32.187: E/AndroidRuntime(18639): at com.openglassquartz.helloglass.CardLaunchService.onStartCommand(CardLaunchService.java:77)
How can I fix this? It seems to work on Netbeans when I tried outputting it but not in Google Glass.
Two things to look at (it looks like your stack trace is cut off in your post):
Did you add the android.permission.INTERNET permission to your application's manifest?
Is this code being called in the main UI thread? Network operations must be executed in a background thread – you may want to look at the AsyncTask class as a way of handling this.

MFC Assertion fails after upgrading from VC++ 6 to MSVC 2005

Is it normal to have to update assertions after upgrading the compiler from VC++ 6 to MSVC 2005? I have the following function which works without triggering the assertion in Visual Studio 6 but anything newer it fails.
void CMainFrame::OnUpdateGraphValue (CCmdUI* pCmdUI) {
BOOL bMax;
CMDIChildWnd *child = MDIGetActive (&bMax);
if (child)
{
if (child->IsKindOf (RUNTIME_CLASS (CGaugeChildFrame)))
{
CGaugeView *pView = (CGaugeView *) child->GetActiveView ();
if (pView->wndActive)
{
ASSERT (pView->IsKindOf (RUNTIME_CLASS (CGaugeView)));
pCmdUI->Enable (TRUE);
return;
}
}
if (child->IsKindOf (RUNTIME_CLASS (CGarterChildFrame)))
{
CGarterView *pView = (CGarterView *) child->GetActiveView ();
if (pView->wndGraphics)
{
ASSERT (pView->IsKindOf (RUNTIME_CLASS (CGarterView)));
pCmdUI->Enable (TRUE);
return;
}
}
}
pCmdUI->Enable (FALSE); }
The failure occurs on line ASSERT (pView->IsKindOf (RUNTIME_CLASS (CGaugeView))); When I click print preview the type is not CGaugeView but CPreviewView.
Can someone please shed some light on this for me? Thanks
It's not valid to cast to a type before you have checked the type is compatible.
So you need to do:
if(child->GetActiveView ()->IsKindOf(RUNTIME_CLASS(CGaugeView)))
{
CGaugeView *pView = (CGaugeView *) child->GetActiveView ();
As to why has this behaviour changed, I don't know. Maybe before you were ignoring the asserts? Maybe you didn't try a debug built?
Or maybe the print preview architecture has changed in version 7? Maybe there was no pView->wndGraphics in print preview mode in the previous version, so the code path never got triggered.
However since you aren't using the code path for anything maybe just dump it.

How to set the exit status in a Groovy Script

We have a Groovy Script that exits with a status of 0 when everything worked and a non-0 status for different types of failure conditions. For example if the script took a user and an email address as arguments it would exit with a status of 1 for an invalid user, and a status of 2 for an invalid email address format. We use System.exit(statusCode) for this. This works fine, but makes the the script difficult to write test cases for.
In a test we create our GroovyShell, create our Binding and call shell.run(script,args). For tests that assert failure conditions, the System.exit() causes the JVM (and the test) to exit.
Are there alternatives to using System.exit() to exit a Groovy Script? I experimented with throwing uncaught exceptions, but that clutters the output and always makes the status code 1.
In our test cases I have also experimented with using System.metaClass.static.invokeMethod to change the behavior of System.exit() to not exit the JVM, but that seems like an ugly hack.
imho System.metaClass.static.invokeMethod looks fine. It's test, and hacking is fine here.
Also you can create your own wrapper around it, like:
class ExitUtils {
static boolean enabled = true
static exit(int code) {
if (!ExitUtils.enabled) {
return //TODO set some flag?
}
System.exit(code)
}
}
and disable it for tests.
Here is the technique we eventually used.
We can't just ignore a call to System.exit() since the script would continue to run. Instead we want to throw an exception with the desired status code. We throw a (custom) ProgramExitException when System.exit() is called in our tests
class ProgramExitException extends RuntimeException {
int statusCode
public ProgramExitException(int statusCode) {
super("Exited with " + statusCode)
this.statusCode = statusCode
}
}
then we intercept System.exit() to throw this exception
/**
* Make System.exit throw ProgramExitException to fake exiting the VM
*/
System.metaClass.static.invokeMethod = { String name, args ->
if (name == 'exit')
throw new ProgramExitException(args[0])
def validMethod = System.metaClass.getStaticMetaMethod(name, args)
if (validMethod != null) {
validMethod.invoke(delegate, args)
}
else {
return System.metaClass.invokeMissingMethod(delegate, name, args)
}
}
and lastly we have GroovyShell catch any ProgramExitException and return the status code from the run method.
/**
* Catch ProgramExitException exceptions to mimic exit status codes
* without exiting the VM
*/
GroovyShell.metaClass.invokeMethod = { String name, args ->
def validMethod = GroovyShell.metaClass.getMetaMethod(name, args)
if (validMethod != null) {
try {
validMethod.invoke(delegate, args)
} catch (ProgramExitException e) {
return e.statusCode
}
}
else {
return GroovyShell.metaClass.invokeMissingMethod(delegate, name, args)
}
}
Our tests can stay looking simple, we don't need to change anything in the scripts and we get the behavior we expect from running on the command line.
assertEquals 'Unexpected status code', 0, shell.run(script,[arg1, arg2])
assertEquals 'Unexpected status code', 10, shell.run(script,[badarg1, badarg2])