Ignore:
Timestamp:
11/24/11 14:45:29 (8 years ago)
Author:
mario
Message:

added minimal changes to compile on a POSIX like OS (mainly Linux)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/legacy/jvmlink/src/main/c++/TestC2.cpp

    r3834 r7812  
    3131*/ 
    3232 
    33 #include "stdafx.h" 
     33#ifdef _WIN32 
     34#include <stdafx.h> 
     35#else 
     36#include <unistd.h> // for usleep() 
     37#endif 
     38 
    3439#include "JVMLinkClient.h" 
     40 
    3541#include <ctime> // for time() 
    3642#include <cstdlib> // for srand() and rand() 
     43#include <iostream> // for cout and cerr 
     44#include <stdio.h> // for getchar 
    3745 
    3846bool randomBool() { 
     
    95103} 
    96104 
    97 void printStrings(CString* values, int len) { 
     105void printStrings(std::string* values, int len) { 
    98106        for (int i=0; i<len; i++) { 
    99107                std::cout << "\t" << values[i] << std::endl; 
     
    102110 
    103111// Tests the JVMLink API. 
    104 int _tmain(int argc, _TCHAR* argv[]) 
     112int main(int argc, char* argv[]) 
    105113{ 
    106114        JVMLinkClient *p = new JVMLinkClient(); 
    107115        p->startJava(20345, "jvmlink.jar"); 
    108         while (p->establishConnection() != JVMLinkClient::CONNECTION_SUCCESS) Sleep(250); 
     116        while (p->establishConnection() != JVMLinkClient::CONNECTION_SUCCESS) { 
     117#ifdef _WIN32 
     118                Sleep(250); 
     119#else 
     120                usleep(250 * 1000); 
     121#endif 
     122        } 
    109123 
    110124        srand((int) time(0)); 
     
    167181        std::cout << "TestC2: getVar: myShort == " << jvmShort->getDataAsShort() << std::endl; 
    168182 
    169         // CString variables 
    170         CString myString = "<<The quick brown fox jumps over the lazy dog.>>"; 
     183        // std::string variables 
     184        std::string myString = "<<The quick brown fox jumps over the lazy dog.>>"; 
    171185        p->setVar("myString", &myString); 
    172186        std::cout << "TestC2: setVar: myString -> " << myString << std::endl; 
     
    208222        } 
    209223 
    210         CString* myStrings = new CString[6]; 
     224        std::string* myStrings = new std::string[6]; 
    211225        myStrings[0] = "\"There was an Old Man with a beard,"; 
    212226        myStrings[1] = "Who said, 'It is just as I feared!"; 
     
    296310        std::cout << " ]" << std::endl; 
    297311 
    298         // CString arrays 
     312        // std::string arrays 
    299313        p->setVar("myStrings", myStrings, 6); 
    300314        std::cout << "TestC2: setVar: myStrings -> [" << std::endl; 
     
    358372        delete largeBytes; 
    359373 
    360         fprintf(stdout, "\n\nPress enter to shut down the server and exit...\n"); 
     374        std::cout << std::endl << std::endl << "Press enter to shut down the server and exit..." << std::endl; 
     375#ifdef _WIN32 
    361376        _fgetchar(); 
     377#else 
     378        getchar(); 
     379#endif 
    362380 
    363381        // free Java resources 
Note: See TracChangeset for help on using the changeset viewer.