~ubuntu-branches/ubuntu/jaunty/cmake/jaunty-security

« back to all changes in this revision

Viewing changes to Tests/Complex/Executable/complex.cxx

  • Committer: Bazaar Package Importer
  • Author(s): A. Maitland Bottoms
  • Date: 2006-06-18 16:34:11 UTC
  • mfrom: (1.4.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20060618163411-pi234s3v6jwlcmof
Tags: 2.4.2-1
* New upstream release (Closes: #338324)
* Put cmake .vim files into /usr/share/vim/addons/plugin/
  where they can be used. (Closes: #366663)
* Install cmake-mode.el so it can be used. (Closes: #366664)
* Ensure cmake FindKDE locates KDE libraries on Debian
  based distributions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
extern "C" {
9
9
#include "testConly.h"
10
10
}
 
11
#ifndef CMAKE_TEST_DIFFERENT_GENERATOR
11
12
#include "cmStandardIncludes.h"
12
13
#include "cmSystemTools.h"
13
14
#include "cmDynamicLoader.h"
14
15
#include "cmSystemTools.h"
15
16
#include "cmOrderLinkDirectories.h"
16
17
#include "cmGeneratedFileStream.h"
 
18
#include <cmsys/DynamicLoader.hxx>
 
19
#else
 
20
#include <vector>
 
21
#include <string>
 
22
#include <iostream>
 
23
#include <string.h>
 
24
#endif
 
25
 
17
26
 
18
27
int cm_passed = 0;
19
28
int cm_failed = 0;
 
29
// ======================================================================
 
30
 
 
31
void cmFailed(const char* Message, const char* m2= "", const char* m3 = "")
 
32
{
 
33
  std::cout << "FAILED: " << Message << m2 << m3 << "\n"; 
 
34
  cm_failed++;
 
35
}
 
36
 
 
37
// ======================================================================
 
38
 
 
39
void cmPassed(const char* Message, const char* m2="")
 
40
{
 
41
  std::cout << "Passed: " << Message << m2 << "\n"; 
 
42
  cm_passed++;
 
43
}
20
44
 
21
45
#ifndef CMAKE_IS_REALLY_FUN
22
46
This is a problem. Looks like ADD_DEFINITIONS and REMOVE_DEFINITIONS does not work
23
47
#endif
 
48
 
 
49
#ifndef CMAKE_TEST_DIFFERENT_GENERATOR
24
50
// Here is a stupid function that tries to use std::string methods
25
51
// so that the dec cxx compiler will instantiate the stuff that
26
52
// we are using from the CMakeLib library....
29
55
  std::string Adir = std::string(BINARY_DIR) + std::string("/A");
30
56
  std::string Bdir = std::string(BINARY_DIR) + std::string("/B");
31
57
  std::string Cdir = std::string(BINARY_DIR) + std::string("/C");
 
58
#ifdef _WIN32
 
59
  // Avoid case problems for windows paths.
 
60
  if(Adir[0] >= 'A' && Adir[0] <= 'Z') { Adir[0] += 'a' - 'A'; }
 
61
  if(Bdir[0] >= 'A' && Bdir[0] <= 'Z') { Bdir[0] += 'a' - 'A'; }
 
62
  if(Cdir[0] >= 'A' && Cdir[0] <= 'Z') { Cdir[0] += 'a' - 'A'; }
 
63
  Adir = cmSystemTools::GetActualCaseForPath(Adir.c_str());
 
64
  Bdir = cmSystemTools::GetActualCaseForPath(Bdir.c_str());
 
65
  Cdir = cmSystemTools::GetActualCaseForPath(Cdir.c_str());
 
66
#endif
32
67
  
33
68
  if(!shouldFail)
34
69
    {
36
71
    rm += "/libA.a";
37
72
    cmSystemTools::RemoveFile(rm.c_str());
38
73
    }
39
 
  cmTarget target;
40
 
  target.AddLinkDirectory(Adir.c_str());
41
 
  target.AddLinkDirectory(Bdir.c_str());
42
 
  target.AddLinkDirectory(Cdir.c_str());
43
 
  target.AddLinkDirectory("/lib/extra/stuff");
44
 
  
 
74
  std::vector<std::string> linkLibraries;
 
75
  std::vector<std::string> linkDirectories;
 
76
  linkDirectories.push_back(Adir);
 
77
  linkDirectories.push_back(Bdir);
 
78
  linkDirectories.push_back(Cdir);
 
79
  linkDirectories.push_back("/lib/extra/stuff");
45
80
  Adir += "/libA.a";
46
81
  Bdir += "/libB.a";
47
82
  Cdir += "/libC.a";
48
 
  
49
 
  target.AddLinkLibrary(Adir.c_str(), cmTarget::GENERAL);
50
 
  target.AddLinkLibrary(Bdir.c_str(), cmTarget::GENERAL);
51
 
  target.AddLinkLibrary(Cdir.c_str(), cmTarget::GENERAL);
52
 
  target.AddLinkLibrary("-lm", cmTarget::GENERAL);
 
83
  linkLibraries.push_back(Adir);
 
84
  linkLibraries.push_back(Bdir);
 
85
  linkLibraries.push_back(Cdir);
 
86
  linkLibraries.push_back("-lm");
53
87
  std::vector<cmStdString> sortedpaths;
54
88
  std::vector<cmStdString> linkItems;
55
89
  cmOrderLinkDirectories orderLibs;
57
91
  orderLibs.AddLinkExtension(".so");
58
92
  orderLibs.AddLinkExtension(".a");
59
93
  orderLibs.SetLinkPrefix("lib");
60
 
  orderLibs.SetLinkInformation(target, cmTarget::GENERAL, "A");
 
94
  cmTargetManifest manifest;
 
95
  orderLibs.SetLinkInformation("test", linkLibraries, linkDirectories,
 
96
                               manifest, "");
61
97
  bool ret = orderLibs.DetermineLibraryPathOrder();
 
98
  if(!ret)
 
99
    {
 
100
    std::cout << orderLibs.GetWarnings() << "\n";
 
101
    }
62
102
  orderLibs.GetLinkerInformation(sortedpaths, linkItems);
63
103
  std::cout << "Sorted Link Paths:\n";
64
104
  for(std::vector<cmStdString>::iterator i = sortedpaths.begin();
100
140
  return ret;
101
141
}
102
142
 
103
 
void ForceStringUse()
104
 
{
105
 
  std::vector<std::string> v;
106
 
  std::vector<std::string> v2;
107
 
  v = v2;
108
 
  std::string cachetest = CACHE_TEST_VAR_INTERNAL;
109
 
  v.push_back(cachetest);
110
 
  v2 = v;
111
 
  std::string x(5,'x');  
112
 
  char buff[5];
113
 
  x.copy(buff, 1, 0);
114
 
  x[0] = 'a';
115
 
  std::string::size_type pos = 0;
116
 
  x.replace(pos, pos, pos, 'x');
117
 
  std::string copy = cachetest;
118
 
  cachetest.find("bar");
119
 
  cachetest.rfind("bar");
120
 
  copy.append(cachetest);
121
 
  copy = cachetest.substr(0, cachetest.size());
122
 
}
123
 
 
124
 
// ======================================================================
125
 
 
126
 
void cmFailed(const char* Message, const char* m2= "", const char* m3 = "")
127
 
{
128
 
  std::cout << "FAILED: " << Message << m2 << m3 << "\n"; 
129
 
  cm_failed++;
130
 
}
131
 
 
132
 
// ======================================================================
133
 
 
134
 
void cmPassed(const char* Message, const char* m2="")
135
 
{
136
 
  std::cout << "Passed: " << Message << m2 << "\n"; 
137
 
  cm_passed++;
138
 
}
139
 
 
140
143
// ======================================================================
141
144
 
142
145
void TestAndRemoveFile(const char* filename) 
259
262
  cmSystemTools::RemoveFile(file2tmp.c_str());
260
263
  cmSystemTools::RemoveFile(file3tmp.c_str());
261
264
}
 
265
#endif
 
266
 
 
267
void ForceStringUse()
 
268
{
 
269
  std::vector<std::string> v;
 
270
  std::vector<std::string> v2;
 
271
  v = v2;
 
272
  std::string cachetest = CACHE_TEST_VAR_INTERNAL;
 
273
  v.push_back(cachetest);
 
274
  v2 = v;
 
275
  std::string x(5,'x');  
 
276
  char buff[5];
 
277
  x.copy(buff, 1, 0);
 
278
  x[0] = 'a';
 
279
  std::string::size_type pos = 0;
 
280
  x.replace(pos, pos, pos, 'x');
 
281
  std::string copy = cachetest;
 
282
  cachetest.find("bar");
 
283
  cachetest.rfind("bar");
 
284
  copy.append(cachetest);
 
285
  copy = cachetest.substr(0, cachetest.size());
 
286
}
 
287
 
 
288
 
262
289
// defined in testcflags.c
263
290
extern "C" int TestCFlags(char* m);
 
291
extern "C" int TestTargetCompileFlags(char* m);
 
292
 
 
293
#if 0
 
294
// defined in  Sub1/NameConflictTest.c
 
295
extern "C" int NameConflictTest1();
 
296
// defined in  Sub2/NameConflictTest.c
 
297
extern "C" int NameConflictTest2();
 
298
#endif
264
299
 
265
300
// ======================================================================
266
301
 
274
309
#endif
275
310
  std::string exe = lib;
276
311
 
 
312
#ifndef CMAKE_TEST_DIFFERENT_GENERATOR  
277
313
  // Test a single character executable to test a: in makefiles
278
314
  exe += "A";
279
315
  exe += cmSystemTools::GetExecutableExtension();
302
338
    cmPassed("run Single Character executable A returned 10 as expected.");
303
339
    }
304
340
  
305
 
  lib += cmDynamicLoader::LibPrefix();
 
341
  lib += CMAKE_SHARED_MODULE_PREFIX;
306
342
  lib += "CMakeTestModule";
307
 
  lib += cmDynamicLoader::LibExtension();
308
 
  cmLibHandle handle = cmDynamicLoader::OpenLibrary(lib.c_str());
 
343
  lib += CMAKE_SHARED_MODULE_SUFFIX;
 
344
  cmsys::DynamicLoader::LibraryHandle handle = cmDynamicLoader::OpenLibrary(lib.c_str());
309
345
  if(!handle)
310
346
    {
311
347
    std::string err = "Can not open CMakeTestModule:\n";
314
350
    }
315
351
  else
316
352
    {
317
 
    cmDynamicLoaderFunction fun = 
318
 
    cmDynamicLoader::GetSymbolAddress(handle, "ModuleFunction"); 
 
353
    cmsys::DynamicLoader::SymbolPointer fun = 
 
354
      cmsys::DynamicLoader::GetSymbolAddress(handle, "ModuleFunction"); 
319
355
    if(!fun)
320
356
      {
321
 
      fun = cmDynamicLoader::GetSymbolAddress(handle, "_ModuleFunction");
 
357
      fun = cmsys::DynamicLoader::GetSymbolAddress(handle, "_ModuleFunction");
322
358
      }
323
359
    typedef int (*TEST_FUNCTION)();
324
360
    TEST_FUNCTION testFun = (TEST_FUNCTION)fun;
353
389
    cmPassed("Call to C sharedFunction from shared library worked.");
354
390
    }
355
391
  
 
392
    // ----------------------------------------------------------------------
 
393
  // Test cmSystemTools::UpperCase
 
394
  std::string str = "abc";
 
395
  std::string strupper = "ABC";
 
396
  if(cmSystemTools::UpperCase(str) == strupper)
 
397
    {
 
398
    cmPassed("cmSystemTools::UpperCase is working");
 
399
    }
 
400
  else
 
401
    {
 
402
    cmFailed("cmSystemTools::UpperCase is working");
 
403
    }    
 
404
#endif
 
405
#if 0
 
406
  if(NameConflictTest1() == 0 && NameConflictTest2() == 0)
 
407
    {
 
408
    cmPassed("Sub dir with same named source works");
 
409
    }
 
410
  else
 
411
    {
 
412
    cmFailed("Sub dir with same named source fails");
 
413
    }
 
414
#endif
356
415
  if(file1() != 1)
357
416
    {
358
417
    cmFailed("Call to file1 function from library failed.");
361
420
    {
362
421
    cmPassed("Call to file1 function returned 1.");
363
422
    }
364
 
 
 
423
#ifndef COMPLEX_TARGET_FLAG
 
424
  cmFailed("COMPILE_FLAGS did not work with SET_TARGET_PROPERTIES");
 
425
#else
 
426
  cmPassed("COMPILE_FLAGS did work with SET_TARGET_PROPERTIES");
 
427
#endif
 
428
  
365
429
  if(file2() != 1)
366
430
    {
367
431
    cmFailed("Call to file2 function from library failed.");
377
441
#endif
378
442
  std::string gen = CMAKE_GENERATOR;
379
443
  // visual studio is currently broken for c flags
 
444
  char msg[1024];
380
445
  if(gen.find("Visual") == gen.npos)
381
446
    {
382
447
#ifdef TEST_C_FLAGS
384
449
#else
385
450
    cmPassed("CMake CMAKE_C_FLAGS are not being passed to c++ files.");
386
451
#endif
387
 
    char msg[1024];
388
452
    if(TestCFlags(msg))
389
453
      {
390
454
      cmPassed(
395
459
      cmFailed(msg);
396
460
      }
397
461
    }
398
 
  
 
462
  if(TestTargetCompileFlags(msg))
 
463
    {
 
464
    cmPassed(msg);
 
465
    }
 
466
  else
 
467
    {
 
468
    cmFailed(msg);
 
469
    }
 
470
 
399
471
  // ----------------------------------------------------------------------
400
472
  // Test ADD_DEFINITIONS
401
473
 
412
484
#endif
413
485
 
414
486
  // ----------------------------------------------------------------------
 
487
  // Test GET_SOURCE_FILE_PROPERTY for location
 
488
#ifndef CMAKE_FOUND_ACXX
 
489
  cmFailed("CMake did not get the location of A.cxx correctly");
 
490
#else
 
491
  cmPassed("CMake found A.cxx properly");
 
492
#endif
 
493
 
 
494
  // ----------------------------------------------------------------------
 
495
  // Test GET_DIRECTORY_PROPERTY for parent
 
496
#ifndef CMAKE_FOUND_PARENT
 
497
  cmFailed("CMake did not get the location of the parent directory properly");
 
498
#else
 
499
  cmPassed("CMake found the parent directory properly");
 
500
#endif
 
501
  
 
502
  // ----------------------------------------------------------------------
 
503
  // Test GET_DIRECTORY_PROPERTY for listfiles
 
504
#ifndef CMAKE_FOUND_LISTFILE_STACK
 
505
  cmFailed("CMake did not get the listfile stack properly");
 
506
#else
 
507
  cmPassed("CMake found the listfile stack properly");
 
508
#endif
 
509
  
 
510
  // ----------------------------------------------------------------------
415
511
  // Test SET, VARIABLE_REQUIRES
416
512
 
417
513
#ifdef SHOULD_NOT_BE_DEFINED
606
702
  cmPassed("SHOULD_BE_DEFINED_EXISTS2 is defined.");
607
703
#endif
608
704
  
 
705
#ifndef SHOULD_BE_DEFINED_IS_DIRECTORY
 
706
  cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_IS_DIRECTORY is not defined.\n");
 
707
#else
 
708
  cmPassed("SHOULD_BE_DEFINED_IS_DIRECTORY is defined.");
 
709
#endif
 
710
 
 
711
#ifndef SHOULD_BE_DEFINED_IS_DIRECTORY2
 
712
  cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_IS_DIRECTORY2 is not defined.\n");
 
713
#else
 
714
  cmPassed("SHOULD_BE_DEFINED_IS_DIRECTORY2 is defined.");
 
715
#endif
 
716
 
609
717
#ifdef SHOULD_NOT_BE_DEFINED_LESS
610
718
  cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_LESS is defined.");
611
719
#else
927
1035
    }
928
1036
#endif
929
1037
 
 
1038
#ifndef CMAKE_TEST_DIFFERENT_GENERATOR  
930
1039
  // ----------------------------------------------------------------------
931
1040
  // Some pre-build/pre-link/post-build custom-commands have been
932
1041
  // attached to the lib (see Library/).
956
1065
  // only created during a build.
957
1066
 
958
1067
  TestAndRemoveFile(BINARY_DIR "/Library/custom_target1.txt");
959
 
 
 
1068
  
960
1069
  // ----------------------------------------------------------------------
961
1070
  // A directory has been created.
962
1071
 
972
1081
  // only created during a build.
973
1082
 
974
1083
  TestAndRemoveFile(BINARY_DIR "/Executable/Temp/complex-required.txt");
 
1084
#endif
975
1085
 
976
1086
  // ----------------------------------------------------------------------
977
1087
  // Test FIND_LIBRARY
1089
1199
    
1090
1200
  
1091
1201
  // ----------------------------------------------------------------------
1092
 
  // Test cmSystemTools::UpperCase
1093
 
  std::string str = "abc";
1094
 
  std::string strupper = "ABC";
1095
 
  if(cmSystemTools::UpperCase(str) == strupper)
1096
 
    {
1097
 
    cmPassed("cmSystemTools::UpperCase is working");
1098
 
    }
1099
 
  else
1100
 
    {
1101
 
    cmFailed("cmSystemTools::UpperCase is working");
1102
 
    }    
1103
 
  
1104
 
  // ----------------------------------------------------------------------
1105
1202
  // Test if IF command inside a FOREACH works.
1106
1203
#if defined(IF_INSIDE_FOREACH_THEN_EXECUTED) && !defined(IF_INSIDE_FOREACH_ELSE_EXECUTED)
1107
1204
  cmPassed("IF inside a FOREACH block works");
1114
1211
#else
1115
1212
  cmFailed("Generated header included by non-generated source failed.");
1116
1213
#endif
1117
 
  
 
1214
  if(SHOULD_BE_ZERO == 0)
 
1215
    {
 
1216
    cmPassed("cmakedefine01 is working for 0");
 
1217
    }
 
1218
  else
 
1219
    {
 
1220
    cmFailed("cmakedefine01 is not working for 0");
 
1221
    }  
 
1222
  if(SHOULD_BE_ONE == 1)
 
1223
    {
 
1224
    cmPassed("cmakedefine01 is working for 1");
 
1225
    }
 
1226
  else
 
1227
    {
 
1228
    cmFailed("cmakedefine01 is not working for 1");
 
1229
    }  
1118
1230
#ifdef FORCE_TEST
1119
1231
  cmFailed("CMake SET CACHE FORCE");
1120
1232
#else
1121
1233
  cmPassed("CMake SET CACHE FORCE");
1122
1234
#endif
1123
1235
 
 
1236
#ifndef CMAKE_TEST_DIFFERENT_GENERATOR
1124
1237
  // first run with shouldFail = true, this will
1125
1238
  // run with A B C as set by the CMakeList.txt file.
1126
1239
  if(!TestLibraryOrder(true))
1142
1255
    {
1143
1256
    cmFailed("CMake cmOrderLinkDirectories failed.");
1144
1257
    }
1145
 
 
1146
1258
  // Test the generated file stream.
1147
1259
  TestCMGeneratedFileSTream();
 
1260
#endif
1148
1261
  
1149
1262
  // ----------------------------------------------------------------------
1150
1263
  // Summary