Wednesday, July 02, 2014

JSON-RPC with Fiddler

Needed to do a HTTP POST with a JSON RPC payload. Searched the web and there where a good explanation on StackOverflow explaining how to send  JSON string with fiddler:
Is it possible to make JSON requests using Fiddler's Request Builder?

Put the information together and adding the request in Raw and do Execute:

POST /StatusV1 HTTP/1.1
Host: localhost:8080
Content-Type: application/json; charset=utf-8
Content-Length: 81

{"method": "confirmRigModeKeySwitched", "params": ["correctPassword!"], "id": 99}





Worked as a charm!

Wednesday, June 25, 2014

error LNK2019: unresolved external symbol. Problem with linker in C++ is starting to give me gray hair.

Got this error message in the linker when I switched the project from statically linked to dynamically linked in the .Pro file:

StatusFacade.obj : error LNK2019: unresolved external symbol "private: enum mgccis::status::dto::StatusRigMode::Status __thiscall mgccis::status::StatusFacade::RigModeStatusToDto(enum mgccis::status::RigModeReply::Status)" (?RigModeStatusToDto@StatusFacade@status@mgccis@@AAE?AW4Status@StatusRigMode@dto@23@W44RigModeReply@23@@Z) referenced in function "public: class QString __thiscall mgccis::status::StatusFacade::getStatus(void)" (?getStatus@StatusFacade@status@mgccis@@QAE?AVQString@@XZ)


I just uncommented this row:
#CONFIG += staticlib #Nessesary only when running unit tests :(

The solution was easy, I had forgotten to set the class name on the methods in the cpp file, an honest mistake to do:
mgccis::status::dto::StatusOverloadTest::Status OverloadTestStatusToDto(mgccis::status::OverloadTestReply::Status overloadTestStatus)

Should be:
mgccis::status::dto::StatusOverloadTest::Status StatusFacade::OverloadTestStatusToDto(mgccis::status::OverloadTestReply::Status overloadTestStatus)


Strange that the linker did not complain when I statically linked the project. :)

Saturday, May 17, 2014

Solved: Qt Segmentation fault on MainWindow show() on line: inline void show() { setVisible(true); }

Writing this down so I'll remember in the future.

The application worked in Qt Creator in Windows, but in Linux we received Segmentation Fault when trying to run the application in the debugger.

Looking at the stacktrace only showed that it crashed in SetVisible on the main window.

0 __strlen_sse2 strlen.S 99 0x7e9520
1 XSetCommand /usr/lib/libX11.so.6 0xdbbb9f
2 XSetWMProperties /usr/lib/libX11.so.6 0xdc0601
3 QWidgetPrivate::create_sys(unsigned long, bool, bool) /opt/qt-4.8.4/lib/libQtGui.so.4 0x110db5e
4 QWidget::create(unsigned long, bool, bool) /opt/qt-4.8.4/lib/libQtGui.so.4 0x10bc73c
5 QWidget::setVisible(bool) /opt/qt-4.8.4/lib/libQtGui.so.4 0x10c20e5
6 QWidget::show qwidget.h 494 0x804fd0c
7 mgccis::shell::MainApplication::InitializeInterface mainapplication.cpp 29 0x804facc
8 main main.cpp 25 0x804efb0



It stopped on the line below, it made no sense all objects where initialized:

#ifndef Q_WS_WINCE
    inline void show() { setVisible(true); }
#else
    void show();
#endif



After some googling of the subject I found this forum post that described a problem that can cause this error message, it's the signature on the MainApplication that can causes the problem:
http://www.qtcentre.org/archive/index.php/t-45135.html?s=ea17a4ab05c00533d49f938c1da47077


But our solutionwas the opposite from the resolution in the forum post. We have our own builder class that gets the arguments from the main method and that passes the argument to the MainApplication, so in our case the solution was to send the argc parameter as value instead of a reference:

So the Change was from:
explicit MainApplication(int &argc, char* argv[]);


To this:
explicit MainApplication(int argc, char** argv);


After the change the application can be debugged in Windows and Linux and the error message made sense, we sent a reference to a temporary instance of the argc to the MainWindow that used when window is shown.

Saturday, April 26, 2014

Solved HP Administrator Tools disabled when trying to enable hardware virtualization for Windows phone emulator.

Got this message when trying to run the windows phone emulator on my new computer an hp folio 9470m:


Clicking on "More information" and you end up on this MSDN article: http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj863509(v=vs.105).aspx

Following the instruction I tried to log in as administrator in the BIOS but all Administrator Tools settings were disabled, could not find out why, the log in seemed to be ok with the credentials.

After searching the hp support forum I finally gave up and started to googling the problem, right a way I found this post on the hp support forum http://h30434.www3.hp.com/t5/Notebook-Operating-Systems-and-Software/All-BIOS-options-are-disabled-grayed-out/td-p/2169837,

You have to log in as guest and set the BIOS administrator password to get the Administrator Tools enabled, really bad UX, why not prompt the user to set the administrator password the first time?

Wednesday, April 23, 2014

Error: Loading plugin error: Cannot load library /usr/local/SomeLib/libSomeLib.so.1.0.0: (/usr/local/SomeLib/libSomeLib.so.1.0.0: undefined symbol: _ZN18SomePluginModuleD1Ev)

Got this annoying error in QPluginLoader when I deployed and tried to run the application. It took a while before i realized what my mistake was.

I accidentally missed to add a implementation for the destructor and that caused the error message, found this forum post that got me in the right direction:
http://www.qtcentre.org/threads/17253-QPluginLoader-doesn-t-load-plugin

.h with destructor:
~SomePluginModule();

.cpp did not have:
SomePluginModule::~SomePluginModule()
{
   //clean up...
}

Friday, March 28, 2014

Sogeti Visual Studio 2013 ALM Roadshow2014, Örnsköldsvik

I went to Sogeti Visual Studio 2013 ALM Roadshow2014, Örnsköldsvik today. Interesting to hear what's new in Visual Studio 2013. 
Here is my notes from today:

Application Insight

Tool for collecting data on apps performance, crash, environment, etc.

VS2013

  • Synchronize settings if you login using live account.
  • Scrollbar that gives meta information about the code.
  • Auto history, keeps track of changes locally, makes it possible to make a diff against older versions. Automatically or by doing snapshots.
  • Peek, Inline navigation between sourcecode files. keeps the code/context during navigating/peeking other files.
  • Code Map (VS Ultimate only), Visualizing the code blocks and how they are related. Also when debugging. (Can be opened in VS Premium)
  • Code Lens (VS Ultimate only), meta data inline in code. Test status, testing, bugs, workitem, code reviews, maintainability etc.
  • Team explorer, some tabs can be made floating and be docked  in other areas in VS.

Agile project management

  • Features can be added on a higher level (New in Team Foundation Server TFS 2013)
  • Easy prioriting items
  • Scrum board, easy to move items.

Microsoft Test Manager

  • Create test plan, connected to sprint.
  • Easy to create test cases
  • Can take a test drive of the product and create test case from the test drive.
  • Test professional (Tester or project manager)
  • VS Premium or Ultimate if developers what the test tools.
  • Using the web tools requires license as above.
  • UI test case using C# can be created from tests.
  • Possible to pause and resume test cases.

Release management

InRelease got bought by Microsoft and was integrated into TFS.
  • Free to use to keep track of releases.
  • But automatic deployment requires license for deployment agent (One deployment agent per VS Ultimate license).

Central, Distributed Versioning

  • Check-out Check-in (TFS 2010)
  • Edit Commit (TFS2012, CVS, Suversion)
  • Comit Push Pull (TFS 2013, GIT)


Friday, February 14, 2014

Solved: error: no match for call to '(QString) (QString&)' when emitting signal in Qt

I had an annoyning error message:
error: no match for call to '(QString) (QString&)'
when compiling my qt application.

Took some time before I found what was wrong, the code looked like this:
QString newValue=QString::number(value,'g',1);

if(newValue != value_)
{
    value_ = newValue;
    emit newValue(value_);
}



The error is that the signal name is the same as the variable:
QString newValue=QString::number(value,'g',1);

if(newValue != value_)
{
    value_ = newValue;
    emit newValue(value_);
}


So the fix is easy, changed the signal name:
QString newValue=QString::number(value,'g',1);

if(newValue != value_)
{
    value_ = newValue;
    emit updateValue(value_);
}


Sunday, February 09, 2014

How to make your blogger blog a pinned site with live tiles in windows 8.1

By using www.buildmypinnedsite.com you can create the metadata tags that needs to be added to your site.

1. Added the name and some color:


2. Added the blogs rss feed http://mathiaswestin.net/feeds/posts/default?alt=rss

3. For my blogger site it created:
<meta name="application-name" content="MathiasWestin.Net"/> <meta name="msapplication-TileColor" content="#666666"/> <meta name="msapplication-notification" content="frequency=30;polling-uri=http://notifications.buildmypinnedsite.com/?feed=http://mathiaswestin.net/feeds/posts/default?alt=rss&id=1;polling-uri2=http://notifications.buildmypinnedsite.com/?feed=http://mathiaswestin.net/feeds/posts/default?alt=rss&id=2;polling-uri3=http://notifications.buildmypinnedsite.com/?feed=http://mathiaswestin.net/feeds/posts/default?alt=rss&id=3;polling-uri4=http://notifications.buildmypinnedsite.com/?feed=http://mathiaswestin.net/feeds/posts/default?alt=rss&id=4;polling-uri5=http://notifications.buildmypinnedsite.com/?feed=http://mathiaswestin.net/feeds/posts/default?alt=rss&id=5; cycle=1"/>
 This was added to the blogger template by editing the HTML like described in  http://blogknowhow.blogspot.se/2009/05/add-meta-tags-to-blogger-for-better-seo.html:

So I added the following directly under the title tag, notice the added if tags needed to work in blogger, not needed if it's your own site:
<b:if cond='data:blog.url == data:blog.homepageUrl'>
    <meta content='MathiasWestin.Net' name='application-name'/>
<meta content='#666666' name='msapplication-TileColor'/>
<meta content='frequency=30;polling-uri=http://notifications.buildmypinnedsite.com/?feed=http://mathiaswestin.net/feeds/posts/default?alt=rss&amp;id=1;polling-uri2=http://notifications.buildmypinnedsite.com/?feed=http://mathiaswestin.net/feeds/posts/default?alt=rss&amp;id=2;polling-uri3=http://notifications.buildmypinnedsite.com/?feed=http://mathiaswestin.net/feeds/posts/default?alt=rss&amp;id=3;polling-uri4=http://notifications.buildmypinnedsite.com/?feed=http://mathiaswestin.net/feeds/posts/default?alt=rss&amp;id=4;polling-uri5=http://notifications.buildmypinnedsite.com/?feed=http://mathiaswestin.net/feeds/posts/default?alt=rss&amp;id=5; cycle=1' name='msapplication-notification'/>
    </b:if>
 In IE open the page, right click and choose favorites, click the pin to start button:

The site is now added to start and it's live tiles are updated from the blogs rss feed.


Saturday, January 11, 2014

Unit testing in Native C++ using Visual Studio 2013

Test driven development TDD is used in many languages. and can be used in c++ as well. The support for unit test in native C++ was added in VS2012 and I thought I'll write a short blog post on how to get started in VS2013. I'll be using VS 2013 Express for Desktop for this blog post.

I'll use a static library but it is possible to add test projects to EXE or DLL projects as well for more information on that see: http://msdn.microsoft.com/en-us/library/hh419385.aspx

Start Visual Studio 2013:

Visual Studio 2013 for Desktop
We start by adding the projects that should be tested MathLibrary and add a test project MathLibraryTests.

Choose "Add project":
Add project from start page

Add project from FILE menu
In the Add Project dialog, change the project to be a Visual C++ win32 project and the Name to be MathLibrary:

   
New Project dialog



In the Win32 Application wizard choose Next:
Win32 Application Wizard - Step 1


 In the Next step choose Static Library:



 Choose finish and the solution and MathLibrary project is created:


Build the MathLibrary project. Note in the output windows that the MathLibrary.lib file ends up in the Debug folder that is in the Solution folder.


Create the Test project by right clicking the solution and choose New Project:

In the New Project dialog, choose a Visual C++ Native Unit Test project and give it the name MathLibraryTests:


Link the MathLibrary with the MathLibraryTests project, this is done with three steps in the MathLibraryTests projects Properties:

1. Add the MathLibrary.lib to the Additional Dependencies in the linker input settings:

2. Add the path to the MathLibrary.lib file in the Additional Library Directories in the linker general settings:

3. Add the include files path in the Include Directories  in the
VC++ Directories:


Rebuild the MathLibraryTests project, The output should say that the build was successful:

The projects are now in place and we can start testing the application functionality. The functionality in this case will take a string with numbers and calculate the sum of the numbers.
 
Add a new unit test CalculatorTests, Right click the test project and choose "Add new item":


In the Add Item dialog, choose Test C++ Unit Test Class and give it the name CalculatorTests:


Add a new test method by renaming TestMethod1 to CalculateSumWithEmptyStringArgumentReturnsZero:
        TEST_METHOD(CalculateSumWithEmptyStringArgumentReturnsZero)
        {
            // TODO: Your test code here
        }

Add the Arrange, Act, Assert AAA implementation in the test method:
        TEST_METHOD(CalculateSumWithEmptyStringArgumentReturnsZero)
        {
            //Arrange
            int expected = 0;
            Calculator calculator{};
            std::string strArgument{ "" };

            //Act
            auto actual = calculator.CalculateSum(strArgument);

            //Assert
            Assert::AreEqual(expected,actual,L"Should return 0",LINE_INFO());

        }

Run the test project:


Failed or in this case a compiler error = Red

The reson is simple we need to implement the class and metod in the MathLibrary.

Right click the MathLibrary project and choose Add class:

Name it Calculator:


Add a  method CalculateSum,
calculator.h:
#pragma once

#include

class Calculator
{
public:
    Calculator();
    ~Calculator();
    int CalculateSum(std::string stringNumbers);
};

calculator.cpp:
#include "stdafx.h"
#include "Calculator.h"


Calculator::Calculator()
{
}


Calculator::~Calculator()
{
}

int Calculator::CalculateSum(std::string stringNumbers)
{
    return 0;
}

Include calculator.h in the CalculatorTests class.

Run the test:



Result passed = Green:


Refactor and clean the code = Refactor

Re run the unit test, so no errors have been added.

Continue by adding a new test...

Test Failed.

Add new functioanlity...

Test passed

Refactor.

Test passed...

Well that's not all there is to it, but it's a start. After a while you will see the need for initializing and clean up as well as Stub, Fake, Mock object. 

Saturday, January 04, 2014

Subversion integration in Microsoft Office

Having a lot of specifications in subversion can be a good way to handles changes, but having to jump to explorer to get a lock or check-in makes you loose focus on what your doing.

There is a great plugin to help you handle Office documents in Subversion. The plugin is called msofficesvn it's easy to install there is only a few files to copy and paste in the correct folders, follow the instructions here and you be fine.

Word
Excel
Powerpoint

Saturday, December 28, 2013

Pencil Project - Tips and Trix

Have been using Pencil project to GUI prototype a project I'm working on. There is a lot of features that might be hard to find info about. Thought I write down a few tips I've found out.

PNG-files can be dragged and dropped in pencil project. When you do this you get a relative path from the project file to the PNG-file. So to make your pencil projects portable or to check in
to a repository make sure that all files that are dragged and dropped are in a sub folder to the project. If you forgot to do this and have moved the project add a sub folder and move all the resource files there and open the project in a text editor for example Notepad++ and change all pathes on the images in the project file.

Ctrl and click on several objects makes it possible to group the objects, this makes you life easy when there starts to be many objects in the design.




Clicking twice on an object makes it possible to rotate the object, by dragging the vertex in the corner.


Thursday, September 26, 2013

Map Collaboration with XSockets and ArcGIS for JavaScript Revisited

Made a blog post approximately two years ago on using XSockets.net and ArcGIS for JavaScript, a lot has happened since my blog post, so I thought it could be interesting to revisit the subject.

Creating a XSockets.net solution is done the same way. What's new is the possibility to create a windows service running the XSockets server using Chocolatey. I will not do this in this post, but I like the idea.

Create New Project. Is done the same way as before:
In VS2012 choose New Project

Create a new ASP.Net MVC 4 Web application
Choose empty web project:
Choose Empty template and Razor view engine


We use Nuget as we did before to import the XSockets.net package:

Install-Package XSockets

Successful installation

The project now have resources added for XSockets.Net


What strikes me is that the need for several projects has disappeared. Everything is neatly in the same project.

For the client side I used the same boilerplate show extent example but with newer ArcGIS for Javascript and XSocket Javascript API to make it easier to follow what changes I needed to do.

Add a new html page in the root of the project:
Add New Item

MapClient.html


Now it's time add the sample code:


Don't forget to set the new page to be the start page of the web application, right click the page in the solution explorer and choose start page.

So with the client side done it's time to setup the server side. Create custom Controller (Controller was called handler before):

We do that by scaffolding a new controller:
Scaffold XSocketController DemoController
 The code that gets created should look like this:
DemoController.cs
Add the following code:

Start the web page by choosing Chrome and start in Visual Studio:

Use the drop down in VS2012 to choose the right browser


This should start the web browser showing a map, start an other chrome instance and copy the adress into that browser. If you did all the steps correct, you will be able to pan the extent in one map and the other browser will follow:
Opened the MapClient.html in two browser windows



Wednesday, September 25, 2013

Visual Studio 2013 Preview - What's new?

A few personal thoughts when testing the Visual Studio 2013 Preview.

The first thing that I noticed was the login. This helps Visual Studio syncing between machines. Is this a good feature?
Well if you are like me having several developer machines at work and home then it might be a good idea. You can change what will be synchronized by changing the settings in Tools | Options.



Second thing is the color schemes, I would argue that is a good feature making it easy to switch between an brighter theme on day time and a darker to use in the evenings. This can also be changed under Tools | Options later on.

The notification in the upper right is good, discrete but let you notice that there are updates to download etc.