Tuesday, February 25, 2014

SyntaxHighlighter

I mentioned in my previous post that I'm using  SyntaxHighlighter. Well, it took some configuring!
First off, I followed this tutorial. But then nothing would happen. Turns out, at least for me, the SyntaxHighlighter.config.clipboardSwf link got converted to the HTML encoding of the quotes, no matter what I did. Then I eventually found out that you need to write like this to prevent encoding (with the CDATA)

And then, all of my links kept getting forwarded to https://alekgorbatchev... (instead of http://) which meant that nothing worked when I tried to preview the page. Turns out this is because of the new browser "feature" that looks for secure webpages if viewed from a secure webpage. And if I previewed the page, blogger (or is it Google Chrome) automatically makes it secure (since the new post page is secure). So if you want to preview it, you should manually remove the https. It has no effect on people viewing the page, since they are viewing the non-secure version when they look at your blog. In any case, this is the final version of what I have before my </head> tag (notice the lack of http: and the agorbatchev.typepad.com/pub/sh/3_0_83 instead of alexgorbatchev.com/pub/sh/current/):



Monday, February 24, 2014

Netbeans and CppUnit on Mac OS X Mavericks

To continue logging my progress with NetBeans.

I wanted to get into this whole unit testing business, since there's never been a class I actually used that for, and a lot of actual jobs want you to know it. So, since NetBeans is my current IDE of choice (I actually do not have a reason  for this, except that I managed to make GDB and C++ work on it) and since the project has a logical folder called "Test Files", I decided to give it a try.

I'm mostly using this guide, but it's sort of misleading, since it's doing CUnit and I wanted to do CppUnit. So, I followed that guide to install CUnit, and then I went on to add a CppUnit, oops. Turns out those two are different, so I had to install the CppUnit also. Which was confusing on Mac OS (I downloaded the file but couldn't figure out how to configure it on the first go through). 

Then I remembered that I have Homebrew installed, so I decided to take full advantage of that. So, I did a:
brew install cppunit
which worked out-of-the-box.

And then I went on following the guide. I wrote the equivalent of their example (yeah, removed the .h includes essentially)
#include <cstdlib>
#include <iostream>

using namespace std;

long factorial(int arg) {
    long result = 1;
    int i;
    for (i = 2; i <= arg; ++i) {
        result *= i;
     }
    return result;
}

int main(int argc, char** argv) {
    printf("Type an integer and press Enter to calculate the integer's factorial: \n");
    int arg;
    cin>>arg;
    cout<<"factorial("<<arg<<") = "<<factorial(arg)<<endl;
    return 0;
}

And then I right-clicked on the cpp file, selected Create Test -> New CppUnit Test, and then selected my cpp file (at the top of the options, which automatically also selected the factorial function). I left everything else default, per the tutorial.

And then I happily right clicked the Test Files logical folder, and selected Test from there, only to get a bunch of errors. Turns out Homebrew doesn't put the cppunit files where Netbeans expects them.

Turns out the newtestclass.h file contains this include
#include <cppunit/extensions/HelperMacros.h>
And the compiler has no idea where to look for that. This was an easy fix:
Preferences -> C/C++ -> Code Assistance -> C++ Compiler

Select Add on the right-hand-side, and add this:
/usr/local/Cellar/cppunit/1.12.1/include
So, that gets rid of the warning, but then the big error came.
/bin/sh: cppunit-config: command not found
along with many other information.

But! If I went to my terminal and ran
cppunit-config
it worked!

So, I googled forever for an answer, which took me through the netbeans.conf file to no avail. The only thing that worked was starting Netbeans from the terminal.


Note: I should now have syntax highlighting here, thanks to Awesome code syntax highlighting made easy and SyntaxHighlighter (which is the main reason I quoted that much code). But it took me forever to get this to work, I'll make another post right after this one.