Permalink
Browse files

Add project samples for C/C++ 1.6

  • Loading branch information...
1 parent f814006 commit 02206016565c8a305b040ce19eebe989589d68ce @racodond racodond committed Sep 13, 2013
Showing with 535 additions and 15 deletions.
  1. +13 −0 projects/languages/c/Prior to version 1.6/c-sonar-runner/README.md
  2. +22 −0 projects/languages/c/Prior to version 1.6/c-sonar-runner/sonar-project.properties
  3. +18 −0 projects/languages/c/Prior to version 1.6/c-sonar-runner/src/main.c
  4. +13 −0 projects/languages/c/c-sonar-runner/README.md
  5. +19 −0 projects/languages/c/c-sonar-runner/sonar-project.properties
  6. +18 −0 projects/languages/c/c-sonar-runner/src/main.c
  7. +13 −0 projects/languages/cpp/Prior to version 1.6/cpp-sonar-runner-cppunit-gcov/README.md
  8. +34 −0 ...ects/languages/cpp/Prior to version 1.6/cpp-sonar-runner-cppunit-gcov/reports/cppunit/cppunit.xml
  9. +15 −0 ...ects/languages/cpp/Prior to version 1.6/cpp-sonar-runner-cppunit-gcov/reports/gcov/example.c.gcov
  10. +19 −0 projects/languages/cpp/Prior to version 1.6/cpp-sonar-runner-cppunit-gcov/sonar-project.properties
  11. +7 −0 projects/languages/cpp/Prior to version 1.6/cpp-sonar-runner-cppunit-gcov/src/example.c
  12. +64 −0 projects/languages/cpp/Prior to version 1.6/cpp-sonar-runner-cppunit-gcov/tests/example.cpp
  13. +13 −0 projects/languages/cpp/Prior to version 1.6/cpp-sonar-runner/README.md
  14. +22 −0 projects/languages/cpp/Prior to version 1.6/cpp-sonar-runner/sonar-project.properties
  15. +51 −0 projects/languages/cpp/Prior to version 1.6/cpp-sonar-runner/src/BiggestUnInt.cc
  16. +7 −0 projects/languages/cpp/Prior to version 1.6/cpp-sonar-runner/src/HelloWorld.cpp
  17. +87 −0 projects/languages/cpp/Prior to version 1.6/cpp-sonar-runner/src/RandDemo.cc
  18. +70 −0 projects/languages/cpp/Prior to version 1.6/cpp-sonar-runner/src/SimpleClass.cc
  19. +18 −0 projects/languages/cpp/Prior to version 1.6/cpp-sonar-runner/src/main.c
  20. +3 −3 projects/languages/cpp/cpp-sonar-runner-cppunit-gcov/README.md
  21. +3 −3 projects/languages/cpp/cpp-sonar-runner-cppunit-gcov/sonar-project.properties
  22. +3 −3 projects/languages/cpp/cpp-sonar-runner/README.md
  23. +3 −6 projects/languages/cpp/cpp-sonar-runner/sonar-project.properties
@@ -0,0 +1,13 @@
+This example demonstrates how to analyze a C project with the SonarQube Runner.
+
+Prerequisites
+=============
+* [SonarQube](http://www.sonarsource.org/downloads/) 3.0 or higher
+* [SonarQube Runner](http://docs.codehaus.org/x/N4KxDQ) 2.0 or higher
+* [SonarSource C/C++ Plugin](http://www.sonarsource.com/products/plugins/languages/cpp/) 1.5.X
+
+Usage
+=====
+* Analyze the project with SonarQube using the SonarQube Runner:
+
+ sonar-runner
@@ -0,0 +1,22 @@
+# Required metadata
+sonar.projectKey=org.codehaus.sonar:simple-c-project
+sonar.projectName=Simple C project analyzed with the SonarQube Runner
+sonar.projectVersion=1.0
+
+# Comma-separated paths to directories with sources (required)
+sonar.sources=src
+
+# Language
+sonar.language=cpp
+
+# Optional comma-separated list of additional libraries folders (such as /usr/include)
+# sonar.cpp.library.directories=lib
+
+# Optional path to the CppCheck program required to activate some CppCheck rules
+# sonar.cpp.cppcheck.path=C:/Program Files/Cppcheck/cppcheck.exe
+
+# Optional specific predefined macros
+# sonar.cpp.predefinedMacros=#define MY_MACRO(a) ((a)+1),#define DEBUG
+
+# Encoding of the source files
+sonar.sourceEncoding=UTF-8
@@ -0,0 +1,18 @@
+#include <stdio.h> /* NOK, according to the MISRA C 2004 20.9 rule, stdio.h must not be used in embedded system's production code */
+
+#include <mylib.h>
+
+/*
+ * Compile & run from current folder:
+ * gcc -Wall -pedantic -std=c99 -I../lib -o main main.c && ./main
+ */
+
+int main(void) {
+ int x = ADD(40, 2);
+
+ if (x != 42)
+ { /* NOK, empty code blocks generate violations */
+ }
+
+ printf("40 + 2 = %d\n", x);
+}
@@ -0,0 +1,13 @@
+This example demonstrates how to analyze a C project with the SonarQube Runner.
+
+Prerequisites
+=============
+* [SonarQube](http://www.sonarsource.org/downloads/) 3.6 or higher
+* [SonarQube Runner](http://docs.codehaus.org/x/N4KxDQ) 2.0 or higher
+* [SonarSource C/C++ Plugin](http://www.sonarsource.com/products/plugins/languages/cpp/) 1.6 or higher
+
+Usage
+=====
+* Analyze the project with SonarQube using the SonarQube Runner:
+
+ sonar-runner
@@ -0,0 +1,19 @@
+# Required metadata
+sonar.projectKey=org.codehaus.sonar:simple-c-project
+sonar.projectName=Simple C project analyzed with the SonarQube Runner
+sonar.projectVersion=1.0
+
+# Comma-separated paths to directories with sources (required)
+sonar.sources=src
+
+# Language
+sonar.language=c
+
+# Optional comma-separated list of additional libraries folders (such as /usr/include)
+# sonar.cfamily.library.directories=lib
+
+# Optional specific predefined macros
+# sonar.cfamily.predefinedMacros=#define MY_MACRO(a) ((a)+1),#define DEBUG
+
+# Encoding of the source files
+sonar.sourceEncoding=UTF-8
@@ -0,0 +1,18 @@
+#include <stdio.h> /* NOK, according to the MISRA C 2004 20.9 rule, stdio.h must not be used in embedded system's production code */
+
+#include <mylib.h>
+
+/*
+ * Compile & run from current folder:
+ * gcc -Wall -pedantic -std=c99 -I../lib -o main main.c && ./main
+ */
+
+int main(void) {
+ int x = ADD(40, 2);
+
+ if (x != 42)
+ { /* NOK, empty code blocks generate violations */
+ }
+
+ printf("40 + 2 = %d\n", x);
+}
@@ -0,0 +1,13 @@
+This example demonstrates how to analyze a C++ project with the SonarQube Runner and how to import CPPUnit and GCOV reports.
+
+Prerequisites
+=============
+* [SonarQube](http://www.sonarsource.org/downloads/) 3.0 or higher
+* [SonarQube Runner](http://docs.codehaus.org/x/N4KxDQ) 2.0 or higher
+* [SonarSource C/C++ Plugin](http://www.sonarsource.com/products/plugins/languages/cpp/) 1.5.X or higher
+
+Usage
+=====
+* Analyze the project with SonarQube using the SonarQube Runner:
+
+ sonar-runner
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding='ISO-8859-1' standalone='yes' ?>
+<TestRun>
+ <FailedTests>
+ <FailedTest id="2">
+ <Name>Test::testAssert</Name>
+ <FailureType>Assertion</FailureType>
+ <Location>
+ <File>../src/example.cpp</File>
+ <Line>31</Line>
+ </Location>
+ <Message>equality assertion failed
+- Expected: 2
+- Actual : 1
+</Message>
+ </FailedTest>
+ <FailedTest id="3">
+ <Name>Test::testException</Name>
+ <FailureType>Error</FailureType>
+ <Message>uncaught exception of unknown type
+</Message>
+ </FailedTest>
+ </FailedTests>
+ <SuccessfulTests>
+ <Test id="1">
+ <Name>Test::testHelloWorld</Name>
+ </Test>
+ </SuccessfulTests>
+ <Statistics>
+ <Tests>3</Tests>
+ <FailuresTotal>2</FailuresTotal>
+ <Errors>1</Errors>
+ <Failures>1</Failures>
+ </Statistics>
+</TestRun>
@@ -0,0 +1,15 @@
+ -: 0:Source:../../src/example.c
+ -: 0:Graph:./example.gcno
+ -: 0:Data:./example.gcda
+ -: 0:Runs:1
+ -: 0:Programs:1
+function main called 1 returned 100% blocks executed 75%
+ 1: 1:int main(int argc) {
+ 1: 2: if (argc == 0) {
+branch 0 taken 0 (fallthrough)
+branch 1 taken 1
+ #####: 3: return 0;
+ -: 4: } else {
+ 1: 5: return 1;
+ -: 6: }
+ -: 7:}
@@ -0,0 +1,19 @@
+# Required metadata
+sonar.projectKey=org.codehaus.sonar:cpp-cppunit-gcov
+sonar.projectName=C++ project analyzed with the SonarQube Runner; CPPUnit and GCOV reports imported
+sonar.projectVersion=1.0
+
+# Language
+sonar.language=cpp
+
+# Comma-separated paths to directories with sources (required)
+sonar.sources=src
+
+# Encoding of the source files
+sonar.sourceEncoding=UTF-8
+
+# Path to the directory containing the CPPUnit reports
+sonar.cpp.cppunit.reportsPath=reports/cppunit
+
+# Path to the directory containing the GCOV reports
+sonar.cpp.gcov.reportsPath=reports/gcov
@@ -0,0 +1,7 @@
+int main(int argc) {
+ if (argc == 0) {
+ return 0;
+ } else {
+ return 1;
+ }
+}
@@ -0,0 +1,64 @@
+//--- Hello, World! for CppUnit
+
+#include <iostream>
+
+#include <cppunit/TestRunner.h>
+#include <cppunit/TestResult.h>
+#include <cppunit/XmlOutputter.h>
+#include <cppunit/TestResultCollector.h>
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/BriefTestProgressListener.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
+class Test : public CPPUNIT_NS::TestCase
+{
+ CPPUNIT_TEST_SUITE(Test);
+ CPPUNIT_TEST(testHelloWorld);
+ CPPUNIT_TEST(testAssert);
+ CPPUNIT_TEST(testException);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ void setUp(void) {}
+ void tearDown(void) {}
+
+ protected:
+ void testHelloWorld(void) {
+ std::cout << "Hello, world!" << std::endl;
+ }
+
+ void testAssert() {
+ CPPUNIT_ASSERT_EQUAL(2, 1);
+ }
+
+ void testException() {
+ throw "runtime exception";
+ }
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(Test);
+
+int main( int ac, char **av ) {
+ //--- Create the event manager and test controller
+ CPPUNIT_NS::TestResult controller;
+
+ //--- Add a listener that colllects test result
+ CPPUNIT_NS::TestResultCollector result;
+ controller.addListener( &result );
+
+ //--- Add a listener that print dots as test run.
+ CPPUNIT_NS::BriefTestProgressListener progress;
+ controller.addListener( &progress );
+
+
+ //--- Add the top suite to the test runner
+ CPPUNIT_NS::TestRunner runner;
+ runner.addTest( CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest() );
+ runner.run( controller );
+
+ std::ofstream xmlout ( "../reports/cppunit.xml" );
+ CPPUNIT_NS::XmlOutputter xmlOutputter ( &result, xmlout );
+ xmlOutputter.write();
+
+ return result.wasSuccessful() ? 0 : 1;
+}
@@ -0,0 +1,13 @@
+This example demonstrates how to analyze a C++ project with the SonarQube Runner.
+
+Prerequisites
+=============
+* [SonarQube](http://www.sonarsource.org/downloads/) 3.0 or higher
+* [SonarQube Runner](http://docs.codehaus.org/x/N4KxDQ) 2.0 or higher
+* [SonarSource C/C++ Plugin](http://www.sonarsource.com/products/plugins/languages/cpp/) 1.5.X
+
+Usage
+=====
+* Analyze the project with SonarQube using the SonarQube Runner:
+
+ sonar-runner
@@ -0,0 +1,22 @@
+# Required metadata
+sonar.projectKey=org.codehaus.sonar:simple-cpp-project
+sonar.projectName=Simple C++ project analyzed with the SonarQube Runner
+sonar.projectVersion=1.0
+
+# Comma-separated paths to directories with sources (required)
+sonar.sources=src
+
+# Language
+sonar.language=cpp
+
+# Optional comma-separated list of additional libraries folders (such as /usr/include)
+# sonar.cpp.library.directories=lib
+
+# Optional path to the CppCheck program required to activate some CppCheck rules
+# sonar.cpp.cppcheck.path=C:/Program Files/Cppcheck/cppcheck.exe
+
+# Optional specific predefined macros
+# sonar.cpp.predefinedMacros=#define MY_MACRO(a) ((a)+1),#define DEBUG
+
+# Encoding of the source files
+sonar.sourceEncoding=UTF-8
@@ -0,0 +1,51 @@
+// BiggestUnInt2.cc
+// usage:
+// BiggestUnInt2 <starting number> (optional argument, default is 1)
+// example:
+// BiggestUnInt2 4194305
+// features:
+
+#include <iostream>
+#include <cstdlib>
+
+using namespace std;
+
+void bitsout( unsigned int n );
+
+int main(int argc, char* argv[])
+{
+ int N=0;
+ unsigned int i=1 , oldi , j ;
+ if(argc>1) {
+ sscanf( argv[1], "%u", &i ) ; // starting value
+ }
+ cout << "#\ti \ti+(i-1)\t2i\n" ;
+ cout << "#\t#### \t#######\t###\n" ;
+ do {
+ oldi = i ;
+ j = i-1 ;
+ j += i ; // this sets j = 2i-1 (we hope)
+ i *= 2 ; // this doubles i (we hope)
+ cout << N << ":\t" << oldi << "\t" << j << "\t" << i << "\t";
+ bitsout(i);
+ cout << endl ;
+ N++;
+ } while ( j+1==i && i!=0 ) ; // keep going until something odd happens
+ // (Under normal arithmetic,
+ // we always expect A: j+1 to equal i, and
+ // we always expect B: i not to be 0
+ // we keep going while _both_ A _and_ B are true.)
+ // ( '&&' means "_and_" )
+}
+
+void bitsout( unsigned int m )
+{
+ int lastbit ;
+ unsigned int two_to_power_i ;
+
+ for ( int i = 31 ; i >= 0 ; i -- ) {
+ two_to_power_i = (1<<i) ;
+ lastbit = ( two_to_power_i & m ) == 0 ? 0 : 1 ;
+ cout << lastbit ;
+ }
+}
@@ -0,0 +1,7 @@
+using namespace std;
+
+int main ()
+{
+ cout << "Hello World!";
+ return 0;
+}
Oops, something went wrong.

0 comments on commit 0220601

Please sign in to comment.