diff options
| author | Chong Yidong | 2009-09-28 23:23:31 +0000 |
|---|---|---|
| committer | Chong Yidong | 2009-09-28 23:23:31 +0000 |
| commit | 74ea13c1a8d63e4f4015e2b9e7e4336e546e7e4a (patch) | |
| tree | d895d7e93cf93022f48bd6d173f616f1bb4b99fc | |
| parent | b9de0a4665563f847bc7c94f8c89180bf2a9f6bd (diff) | |
| download | emacs-74ea13c1a8d63e4f4015e2b9e7e4336e546e7e4a.tar.gz emacs-74ea13c1a8d63e4f4015e2b9e7e4336e546e7e4a.zip | |
Add CEDET tests.
33 files changed, 6292 insertions, 0 deletions
diff --git a/test/cedet/cedet-utests.el b/test/cedet/cedet-utests.el new file mode 100644 index 00000000000..fe8bad80e66 --- /dev/null +++ b/test/cedet/cedet-utests.el | |||
| @@ -0,0 +1,515 @@ | |||
| 1 | ;;; cedet-utests.el --- Run all unit tests in the CEDET suite. | ||
| 2 | |||
| 3 | ;; Copyright (C) 2008, 2009 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | ;; Author: Eric M. Ludlam <eric@siege-engine.com> | ||
| 6 | |||
| 7 | ;; This file is part of GNU Emacs. | ||
| 8 | |||
| 9 | ;; GNU Emacs is free software: you can redistribute it and/or modify | ||
| 10 | ;; it under the terms of the GNU General Public License as published by | ||
| 11 | ;; the Free Software Foundation, either version 3 of the License, or | ||
| 12 | ;; (at your option) any later version. | ||
| 13 | |||
| 14 | ;; GNU Emacs is distributed in the hope that it will be useful, | ||
| 15 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 16 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 17 | ;; GNU General Public License for more details. | ||
| 18 | |||
| 19 | ;; You should have received a copy of the GNU General Public License | ||
| 20 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | ||
| 21 | |||
| 22 | ;;; Commentary: | ||
| 23 | ;; | ||
| 24 | ;; Remembering to run all the unit tests available in CEDET one at a | ||
| 25 | ;; time is a bit time consuming. This links all the tests together | ||
| 26 | ;; into one command. | ||
| 27 | |||
| 28 | (require 'cedet) | ||
| 29 | ;;; Code: | ||
| 30 | (defvar cedet-utest-test-alist | ||
| 31 | '( | ||
| 32 | ;; | ||
| 33 | ;; COMMON | ||
| 34 | ;; | ||
| 35 | |||
| 36 | ;; Test inversion | ||
| 37 | ("inversion" . inversion-unit-test) | ||
| 38 | |||
| 39 | ;; EZ Image dumping. | ||
| 40 | ("ezimage associations" . ezimage-image-association-dump) | ||
| 41 | ("ezimage images" . ezimage-image-dump) | ||
| 42 | |||
| 43 | ;; Pulse | ||
| 44 | ("pulse interactive test" . (lambda () (pulse-test t))) | ||
| 45 | |||
| 46 | ;; Files | ||
| 47 | ("cedet file conversion" . cedet-files-utest) | ||
| 48 | |||
| 49 | ;; | ||
| 50 | ;; EIEIO | ||
| 51 | ;; | ||
| 52 | ("eieio" . (lambda () (let ((lib (locate-library "eieio-tests.el" | ||
| 53 | t))) | ||
| 54 | (load-file lib)))) | ||
| 55 | ("eieio: browser" . eieio-browse) | ||
| 56 | ("eieio: custom" . (lambda () | ||
| 57 | (require 'eieio-custom) | ||
| 58 | (customize-variable 'eieio-widget-test))) | ||
| 59 | ("eieio: chart" . (lambda () | ||
| 60 | (if (cedet-utest-noninteractive) | ||
| 61 | (message " ** Skipping test in noninteractive mode.") | ||
| 62 | (chart-test-it-all)))) | ||
| 63 | ;; | ||
| 64 | ;; EDE | ||
| 65 | ;; | ||
| 66 | |||
| 67 | ;; @todo - Currently handled in the integration tests. Need | ||
| 68 | ;; some simpler unit tests here. | ||
| 69 | |||
| 70 | ;; | ||
| 71 | ;; SEMANTIC | ||
| 72 | ;; | ||
| 73 | ("semantic: lex spp table write" . semantic-lex-spp-write-utest) | ||
| 74 | ("semantic: multi-lang parsing" . semantic-utest-main) | ||
| 75 | ("semantic: C preprocessor" . semantic-utest-c) | ||
| 76 | ("semantic: analyzer tests" . semantic-ia-utest) | ||
| 77 | ("semanticdb: data cache" . semantic-test-data-cache) | ||
| 78 | ("semantic: throw-on-input" . | ||
| 79 | (lambda () | ||
| 80 | (if (cedet-utest-noninteractive) | ||
| 81 | (message " ** Skipping test in noninteractive mode.") | ||
| 82 | (semantic-test-throw-on-input)))) | ||
| 83 | |||
| 84 | ("semantic: gcc: output parse test" . semantic-gcc-test-output-parser) | ||
| 85 | ;; | ||
| 86 | ;; SRECODE | ||
| 87 | ;; | ||
| 88 | ("srecode: fields" . srecode-field-utest) | ||
| 89 | ("srecode: templates" . srecode-utest-template-output) | ||
| 90 | ("srecode: show maps" . srecode-get-maps) | ||
| 91 | ("srecode: getset" . srecode-utest-getset-output) | ||
| 92 | ) | ||
| 93 | "Alist of all the tests in CEDET we should run.") | ||
| 94 | |||
| 95 | (defvar cedet-running-master-tests nil | ||
| 96 | "Non-nil when CEDET-utest is running all the tests.") | ||
| 97 | |||
| 98 | (defun cedet-utest (&optional exit-on-error) | ||
| 99 | "Run the CEDET unittests. | ||
| 100 | EXIT-ON-ERROR causes the test suite to exit on an error, instead | ||
| 101 | of just logging the error." | ||
| 102 | (interactive) | ||
| 103 | (if (or (not (featurep 'semanticdb-mode)) | ||
| 104 | (not (semanticdb-minor-mode-p))) | ||
| 105 | (error "CEDET Tests require: M-x semantic-load-enable-minimum-features")) | ||
| 106 | (cedet-utest-log-setup "ALL TESTS") | ||
| 107 | (let ((tl cedet-utest-test-alist) | ||
| 108 | (notes nil) | ||
| 109 | (err nil) | ||
| 110 | (start (current-time)) | ||
| 111 | (end nil) | ||
| 112 | (cedet-running-master-tests t) | ||
| 113 | ) | ||
| 114 | (dolist (T tl) | ||
| 115 | (cedet-utest-add-log-item-start (car T)) | ||
| 116 | (setq notes nil err nil) | ||
| 117 | (condition-case Cerr | ||
| 118 | (progn | ||
| 119 | (funcall (cdr T)) | ||
| 120 | ) | ||
| 121 | (error | ||
| 122 | (setq err (format "ERROR: %S" Cerr)) | ||
| 123 | ;;(message "Error caught: %s" Cerr) | ||
| 124 | )) | ||
| 125 | |||
| 126 | ;; Cleanup stray input and events that are in the way. | ||
| 127 | ;; Not doing this causes sit-for to not refresh the screen. | ||
| 128 | ;; Doing this causes the user to need to press keys more frequently. | ||
| 129 | (when (and (interactive-p) (input-pending-p)) | ||
| 130 | (if (fboundp 'read-event) | ||
| 131 | (read-event) | ||
| 132 | (read-char))) | ||
| 133 | |||
| 134 | (cedet-utest-add-log-item-done notes err) | ||
| 135 | (when (and exit-on-error err) | ||
| 136 | (message "to debug this test point, execute:") | ||
| 137 | (message "%S" (cdr T)) | ||
| 138 | (message "\n ** Exiting Test Suite. ** \n") | ||
| 139 | (throw 'cedet-utest-exit-on-error t) | ||
| 140 | ) | ||
| 141 | ) | ||
| 142 | (setq end (current-time)) | ||
| 143 | (cedet-utest-log-shutdown-msg "ALL TESTS" start end) | ||
| 144 | nil)) | ||
| 145 | |||
| 146 | (defun cedet-utest-noninteractive () | ||
| 147 | "Return non-nil if running non-interactively." | ||
| 148 | (if (featurep 'xemacs) | ||
| 149 | (noninteractive) | ||
| 150 | noninteractive)) | ||
| 151 | |||
| 152 | ;;;###autoload | ||
| 153 | (defun cedet-utest-batch () | ||
| 154 | "Run the CEDET unit test in BATCH mode." | ||
| 155 | (unless (cedet-utest-noninteractive) | ||
| 156 | (error "`cedet-utest-batch' is to be used only with -batch")) | ||
| 157 | (condition-case err | ||
| 158 | (when (catch 'cedet-utest-exit-on-error | ||
| 159 | ;; Get basic semantic features up. | ||
| 160 | (semantic-load-enable-minimum-features) | ||
| 161 | ;; Disables all caches related to semantic DB so all | ||
| 162 | ;; tests run as if we have bootstrapped CEDET for the | ||
| 163 | ;; first time. | ||
| 164 | (setq-default semanticdb-new-database-class 'semanticdb-project-database) | ||
| 165 | (message "Disabling existing Semantic Database Caches.") | ||
| 166 | |||
| 167 | ;; Disabling the srecoder map, we won't load a pre-existing one | ||
| 168 | ;; and will be forced to bootstrap a new one. | ||
| 169 | (setq srecode-map-save-file nil) | ||
| 170 | |||
| 171 | ;; Run the tests | ||
| 172 | (cedet-utest t) | ||
| 173 | ) | ||
| 174 | (kill-emacs 1)) | ||
| 175 | (error | ||
| 176 | (error "Error in unit test harness:\n %S" err)) | ||
| 177 | ) | ||
| 178 | ) | ||
| 179 | |||
| 180 | ;;; Logging utility. | ||
| 181 | ;; | ||
| 182 | (defvar cedet-utest-frame nil | ||
| 183 | "Frame used during cedet unit test logging.") | ||
| 184 | (defvar cedet-utest-buffer nil | ||
| 185 | "Frame used during cedet unit test logging.") | ||
| 186 | (defvar cedet-utest-frame-parameters | ||
| 187 | '((name . "CEDET-UTEST") | ||
| 188 | (width . 80) | ||
| 189 | (height . 25) | ||
| 190 | (minibuffer . t)) | ||
| 191 | "Frame parameters used for the cedet utest log frame.") | ||
| 192 | |||
| 193 | (defvar cedet-utest-last-log-item nil | ||
| 194 | "Remember the last item we were logging for.") | ||
| 195 | |||
| 196 | (defvar cedet-utest-log-timer nil | ||
| 197 | "During a test, track the start time.") | ||
| 198 | |||
| 199 | (defun cedet-utest-log-setup (&optional title) | ||
| 200 | "Setup a frame and buffer for unit testing. | ||
| 201 | Optional argument TITLE is the title of this testing session." | ||
| 202 | (setq cedet-utest-log-timer (current-time)) | ||
| 203 | (if (cedet-utest-noninteractive) | ||
| 204 | (message "\n>> Setting up %s tests to run @ %s\n" | ||
| 205 | (or title "") | ||
| 206 | (current-time-string)) | ||
| 207 | |||
| 208 | ;; Interactive mode needs a frame and buffer. | ||
| 209 | (when (or (not cedet-utest-frame) (not (frame-live-p cedet-utest-frame))) | ||
| 210 | (setq cedet-utest-frame (make-frame cedet-utest-frame-parameters))) | ||
| 211 | (when (or (not cedet-utest-buffer) (not (buffer-live-p cedet-utest-buffer))) | ||
| 212 | (setq cedet-utest-buffer (get-buffer-create "*CEDET utest log*"))) | ||
| 213 | (save-excursion | ||
| 214 | (set-buffer cedet-utest-buffer) | ||
| 215 | (setq cedet-utest-last-log-item nil) | ||
| 216 | (when (not cedet-running-master-tests) | ||
| 217 | (erase-buffer)) | ||
| 218 | (insert "\n\nSetting up " | ||
| 219 | (or title "") | ||
| 220 | " tests to run @ " (current-time-string) "\n\n")) | ||
| 221 | (let ((oframe (selected-frame))) | ||
| 222 | (unwind-protect | ||
| 223 | (progn | ||
| 224 | (select-frame cedet-utest-frame) | ||
| 225 | (switch-to-buffer cedet-utest-buffer t)) | ||
| 226 | (select-frame oframe))) | ||
| 227 | )) | ||
| 228 | |||
| 229 | (defun cedet-utest-elapsed-time (start end) | ||
| 230 | "Copied from elp.el. Was elp-elapsed-time. | ||
| 231 | Argument START and END bound the time being calculated." | ||
| 232 | (+ (* (- (car end) (car start)) 65536.0) | ||
| 233 | (- (car (cdr end)) (car (cdr start))) | ||
| 234 | (/ (- (car (cdr (cdr end))) (car (cdr (cdr start)))) 1000000.0))) | ||
| 235 | |||
| 236 | (defun cedet-utest-log-shutdown (title &optional errorcondition) | ||
| 237 | "Shut-down a larger test suite. | ||
| 238 | TITLE is the section that is done. | ||
| 239 | ERRORCONDITION is some error that may have occured durinig testing." | ||
| 240 | (let ((endtime (current-time)) | ||
| 241 | ) | ||
| 242 | (cedet-utest-log-shutdown-msg title cedet-utest-log-timer endtime) | ||
| 243 | (setq cedet-utest-log-timer nil) | ||
| 244 | )) | ||
| 245 | |||
| 246 | (defun cedet-utest-log-shutdown-msg (title startime endtime) | ||
| 247 | "Show a shutdown message with TITLE, STARTIME, and ENDTIME." | ||
| 248 | (if (cedet-utest-noninteractive) | ||
| 249 | (progn | ||
| 250 | (message "\n>> Test Suite %s ended at @ %s" | ||
| 251 | title | ||
| 252 | (format-time-string "%c" endtime)) | ||
| 253 | (message " Elapsed Time %.2f Seconds\n" | ||
| 254 | (cedet-utest-elapsed-time startime endtime))) | ||
| 255 | |||
| 256 | (save-excursion | ||
| 257 | (set-buffer cedet-utest-buffer) | ||
| 258 | (goto-char (point-max)) | ||
| 259 | (insert "\n>> Test Suite " title " ended at @ " | ||
| 260 | (format-time-string "%c" endtime) "\n" | ||
| 261 | " Elapsed Time " | ||
| 262 | (number-to-string | ||
| 263 | (cedet-utest-elapsed-time startime endtime)) | ||
| 264 | " Seconds\n * ")) | ||
| 265 | )) | ||
| 266 | |||
| 267 | (defun cedet-utest-show-log-end () | ||
| 268 | "Show the end of the current unit test log." | ||
| 269 | (unless (cedet-utest-noninteractive) | ||
| 270 | (let* ((cb (current-buffer)) | ||
| 271 | (cf (selected-frame)) | ||
| 272 | (bw (or (get-buffer-window cedet-utest-buffer t) | ||
| 273 | (get-buffer-window (switch-to-buffer cedet-utest-buffer) t))) | ||
| 274 | (lf (window-frame bw)) | ||
| 275 | ) | ||
| 276 | (select-frame lf) | ||
| 277 | (select-window bw) | ||
| 278 | (goto-char (point-max)) | ||
| 279 | (select-frame cf) | ||
| 280 | (set-buffer cb) | ||
| 281 | ))) | ||
| 282 | |||
| 283 | (defun cedet-utest-post-command-hook () | ||
| 284 | "Hook run after the current log command was run." | ||
| 285 | (if (cedet-utest-noninteractive) | ||
| 286 | (message "") | ||
| 287 | (save-excursion | ||
| 288 | (set-buffer cedet-utest-buffer) | ||
| 289 | (goto-char (point-max)) | ||
| 290 | (insert "\n\n"))) | ||
| 291 | (setq cedet-utest-last-log-item nil) | ||
| 292 | (remove-hook 'post-command-hook 'cedet-utest-post-command-hook) | ||
| 293 | ) | ||
| 294 | |||
| 295 | (defun cedet-utest-add-log-item-start (item) | ||
| 296 | "Add ITEM into the log as being started." | ||
| 297 | (unless (equal item cedet-utest-last-log-item) | ||
| 298 | (setq cedet-utest-last-log-item item) | ||
| 299 | ;; This next line makes sure we clear out status during logging. | ||
| 300 | (add-hook 'post-command-hook 'cedet-utest-post-command-hook) | ||
| 301 | |||
| 302 | (if (cedet-utest-noninteractive) | ||
| 303 | (message " - Running %s ..." item) | ||
| 304 | (save-excursion | ||
| 305 | (set-buffer cedet-utest-buffer) | ||
| 306 | (goto-char (point-max)) | ||
| 307 | (when (not (bolp)) (insert "\n")) | ||
| 308 | (insert "Running " item " ... ") | ||
| 309 | (sit-for 0) | ||
| 310 | )) | ||
| 311 | (cedet-utest-show-log-end) | ||
| 312 | )) | ||
| 313 | |||
| 314 | (defun cedet-utest-add-log-item-done (&optional notes err precr) | ||
| 315 | "Add into the log that the last item is done. | ||
| 316 | Apply NOTES to the doneness of the log. | ||
| 317 | Apply ERR if there was an error in previous item. | ||
| 318 | Optional argument PRECR indicates to prefix the done msg w/ a newline." | ||
| 319 | (if (cedet-utest-noninteractive) | ||
| 320 | ;; Non-interactive-mode - show a message. | ||
| 321 | (if notes | ||
| 322 | (message " * %s {%s}" (or err "done") notes) | ||
| 323 | (message " * %s" (or err "done"))) | ||
| 324 | ;; Interactive-mode - insert into the buffer. | ||
| 325 | (save-excursion | ||
| 326 | (set-buffer cedet-utest-buffer) | ||
| 327 | (goto-char (point-max)) | ||
| 328 | (when precr (insert "\n")) | ||
| 329 | (if err | ||
| 330 | (insert err) | ||
| 331 | (insert "done") | ||
| 332 | (when notes (insert " (" notes ")"))) | ||
| 333 | (insert "\n") | ||
| 334 | (setq cedet-utest-last-log-item nil) | ||
| 335 | (sit-for 0) | ||
| 336 | ))) | ||
| 337 | |||
| 338 | ;;; INDIVIDUAL TEST API | ||
| 339 | ;; | ||
| 340 | ;; Use these APIs to start and log information. | ||
| 341 | ;; | ||
| 342 | ;; The other fcns will be used to log across all the tests at once. | ||
| 343 | (defun cedet-utest-log-start (testname) | ||
| 344 | "Setup the log for the test TESTNAME." | ||
| 345 | ;; Make sure we have a log buffer. | ||
| 346 | (save-window-excursion | ||
| 347 | (when (or (not cedet-utest-buffer) | ||
| 348 | (not (buffer-live-p cedet-utest-buffer)) | ||
| 349 | (not (get-buffer-window cedet-utest-buffer t)) | ||
| 350 | ) | ||
| 351 | (cedet-utest-log-setup)) | ||
| 352 | ;; Add our startup message. | ||
| 353 | (cedet-utest-add-log-item-start testname) | ||
| 354 | )) | ||
| 355 | |||
| 356 | (defun cedet-utest-log(format &rest args) | ||
| 357 | "Log the text string FORMAT. | ||
| 358 | The rest of the ARGS are used to fill in FORMAT with `format'." | ||
| 359 | (if (cedet-utest-noninteractive) | ||
| 360 | (apply 'message format args) | ||
| 361 | (save-excursion | ||
| 362 | (set-buffer cedet-utest-buffer) | ||
| 363 | (goto-char (point-max)) | ||
| 364 | (when (not (bolp)) (insert "\n")) | ||
| 365 | (insert (apply 'format format args)) | ||
| 366 | (insert "\n") | ||
| 367 | (sit-for 0) | ||
| 368 | )) | ||
| 369 | (cedet-utest-show-log-end) | ||
| 370 | ) | ||
| 371 | |||
| 372 | ;;; Inversion tests | ||
| 373 | |||
| 374 | (defun inversion-unit-test () | ||
| 375 | "Test inversion to make sure it can identify different version strings." | ||
| 376 | (interactive) | ||
| 377 | (let ((c1 (inversion-package-version 'inversion)) | ||
| 378 | (c1i (inversion-package-incompatibility-version 'inversion)) | ||
| 379 | (c2 (inversion-decode-version "1.3alpha2")) | ||
| 380 | (c3 (inversion-decode-version "1.3beta4")) | ||
| 381 | (c4 (inversion-decode-version "1.3 beta5")) | ||
| 382 | (c5 (inversion-decode-version "1.3.4")) | ||
| 383 | (c6 (inversion-decode-version "2.3alpha")) | ||
| 384 | (c7 (inversion-decode-version "1.3")) | ||
| 385 | (c8 (inversion-decode-version "1.3pre1")) | ||
| 386 | (c9 (inversion-decode-version "2.4 (patch 2)")) | ||
| 387 | (c10 (inversion-decode-version "2.4 (patch 3)")) | ||
| 388 | (c11 (inversion-decode-version "2.4.2.1")) | ||
| 389 | (c12 (inversion-decode-version "2.4.2.2")) | ||
| 390 | ) | ||
| 391 | (if (not (and | ||
| 392 | (inversion-= c1 c1) | ||
| 393 | (inversion-< c1i c1) | ||
| 394 | (inversion-< c2 c3) | ||
| 395 | (inversion-< c3 c4) | ||
| 396 | (inversion-< c4 c5) | ||
| 397 | (inversion-< c5 c6) | ||
| 398 | (inversion-< c2 c4) | ||
| 399 | (inversion-< c2 c5) | ||
| 400 | (inversion-< c2 c6) | ||
| 401 | (inversion-< c3 c5) | ||
| 402 | (inversion-< c3 c6) | ||
| 403 | (inversion-< c7 c6) | ||
| 404 | (inversion-< c4 c7) | ||
| 405 | (inversion-< c2 c7) | ||
| 406 | (inversion-< c8 c6) | ||
| 407 | (inversion-< c8 c7) | ||
| 408 | (inversion-< c4 c8) | ||
| 409 | (inversion-< c2 c8) | ||
| 410 | (inversion-< c9 c10) | ||
| 411 | (inversion-< c10 c11) | ||
| 412 | (inversion-< c11 c12) | ||
| 413 | ;; Negatives | ||
| 414 | (not (inversion-< c3 c2)) | ||
| 415 | (not (inversion-< c4 c3)) | ||
| 416 | (not (inversion-< c5 c4)) | ||
| 417 | (not (inversion-< c6 c5)) | ||
| 418 | (not (inversion-< c7 c2)) | ||
| 419 | (not (inversion-< c7 c8)) | ||
| 420 | (not (inversion-< c12 c11)) | ||
| 421 | ;; Test the tester on inversion | ||
| 422 | (not (inversion-test 'inversion inversion-version)) | ||
| 423 | ;; Test that we throw an error | ||
| 424 | (inversion-test 'inversion "0.0.0") | ||
| 425 | (inversion-test 'inversion "1000.0") | ||
| 426 | )) | ||
| 427 | (error "Inversion tests failed") | ||
| 428 | (message "Inversion tests passed.")))) | ||
| 429 | |||
| 430 | ;;; cedet-files unit test | ||
| 431 | |||
| 432 | (defvar cedet-files-utest-list | ||
| 433 | '( | ||
| 434 | ( "/home/me/src/myproj/src/foo.c" . "!home!me!src!myproj!src!foo.c" ) | ||
| 435 | ( "c:/work/myproj/foo.el" . "!drive_c!work!myproj!foo.el" ) | ||
| 436 | ( "//windows/proj/foo.java" . "!!windows!proj!foo.java" ) | ||
| 437 | ( "/home/me/proj!bang/foo.c" . "!home!me!proj!!bang!foo.c" ) | ||
| 438 | ) | ||
| 439 | "List of different file names to test. | ||
| 440 | Each entry is a cons cell of ( FNAME . CONVERTED ) | ||
| 441 | where FNAME is some file name, and CONVERTED is what it should be | ||
| 442 | converted into.") | ||
| 443 | |||
| 444 | (defun cedet-files-utest () | ||
| 445 | "Test out some file name conversions." | ||
| 446 | (interactive) | ||
| 447 | (let ((idx 0)) | ||
| 448 | (dolist (FT cedet-files-utest-list) | ||
| 449 | |||
| 450 | (setq idx (+ idx 1)) | ||
| 451 | |||
| 452 | (let ((dir->file (cedet-directory-name-to-file-name (car FT) t)) | ||
| 453 | (file->dir (cedet-file-name-to-directory-name (cdr FT) t)) | ||
| 454 | ) | ||
| 455 | |||
| 456 | (unless (string= (cdr FT) dir->file) | ||
| 457 | (error "Failed: %d. Found: %S Wanted: %S" | ||
| 458 | idx dir->file (cdr FT)) | ||
| 459 | ) | ||
| 460 | |||
| 461 | (unless (string= file->dir (car FT)) | ||
| 462 | (error "Failed: %d. Found: %S Wanted: %S" | ||
| 463 | idx file->dir (car FT))))))) | ||
| 464 | |||
| 465 | ;;; pulse test | ||
| 466 | |||
| 467 | (defun pulse-test (&optional no-error) | ||
| 468 | "Test the lightening function for pulsing a line. | ||
| 469 | When optional NO-ERROR Don't throw an error if we can't run tests." | ||
| 470 | (interactive) | ||
| 471 | (if (or (not pulse-flag) (not (pulse-available-p))) | ||
| 472 | (if no-error | ||
| 473 | nil | ||
| 474 | (error (concat "Pulse test only works on versions of Emacs" | ||
| 475 | " that support pulsing"))) | ||
| 476 | ;; Run the tests | ||
| 477 | (when (interactive-p) | ||
| 478 | (message "<Press a key> Pulse one line.") | ||
| 479 | (read-char)) | ||
| 480 | (pulse-momentary-highlight-one-line (point)) | ||
| 481 | (when (interactive-p) | ||
| 482 | (message "<Press a key> Pulse a region.") | ||
| 483 | (read-char)) | ||
| 484 | (pulse-momentary-highlight-region (point) | ||
| 485 | (save-excursion | ||
| 486 | (condition-case nil | ||
| 487 | (forward-char 30) | ||
| 488 | (error nil)) | ||
| 489 | (point))) | ||
| 490 | (when (interactive-p) | ||
| 491 | (message "<Press a key> Pulse line a specific color.") | ||
| 492 | (read-char)) | ||
| 493 | (pulse-momentary-highlight-one-line (point) 'modeline) | ||
| 494 | (when (interactive-p) | ||
| 495 | (message "<Press a key> Pulse a pre-existing overlay.") | ||
| 496 | (read-char)) | ||
| 497 | (let* ((start (point-at-bol)) | ||
| 498 | (end (save-excursion | ||
| 499 | (end-of-line) | ||
| 500 | (when (not (eobp)) | ||
| 501 | (forward-char 1)) | ||
| 502 | (point))) | ||
| 503 | (o (make-overlay start end)) | ||
| 504 | ) | ||
| 505 | (pulse-momentary-highlight-overlay o) | ||
| 506 | (if (overlay-buffer o) | ||
| 507 | (delete-overlay o) | ||
| 508 | (error "Non-temporary overlay was deleted!")) | ||
| 509 | ) | ||
| 510 | (when (interactive-p) | ||
| 511 | (message "Done!")))) | ||
| 512 | |||
| 513 | (provide 'cedet-utests) | ||
| 514 | |||
| 515 | ;;; cedet-utests.el ends here | ||
diff --git a/test/cedet/ede-tests.el b/test/cedet/ede-tests.el new file mode 100644 index 00000000000..6b08994e0bc --- /dev/null +++ b/test/cedet/ede-tests.el | |||
| @@ -0,0 +1,58 @@ | |||
| 1 | ;;; From ede-locate: | ||
| 2 | |||
| 3 | (require 'ede/locate) | ||
| 4 | |||
| 5 | ;;; TESTS | ||
| 6 | ;; | ||
| 7 | ;; Some testing routines. | ||
| 8 | (defun ede-locate-test-locate (file) | ||
| 9 | "Test EDE Locate on FILE using LOCATE type. | ||
| 10 | The search is done with the current EDE root." | ||
| 11 | (interactive "sFile: ") | ||
| 12 | (let ((loc (ede-locate-locate | ||
| 13 | "test" | ||
| 14 | :root (ede-project-root-directory | ||
| 15 | (ede-toplevel))))) | ||
| 16 | (data-debug-new-buffer "*EDE Locate ADEBUG*") | ||
| 17 | (ede-locate-file-in-project loc file) | ||
| 18 | (data-debug-insert-object-slots loc "]")) | ||
| 19 | ) | ||
| 20 | |||
| 21 | (defun ede-locate-test-global (file) | ||
| 22 | "Test EDE Locate on FILE using GNU Global type. | ||
| 23 | The search is done with the current EDE root." | ||
| 24 | (interactive "sFile: ") | ||
| 25 | (let ((loc (ede-locate-global | ||
| 26 | "test" | ||
| 27 | :root (ede-project-root-directory | ||
| 28 | (ede-toplevel))))) | ||
| 29 | (data-debug-new-buffer "*EDE Locate ADEBUG*") | ||
| 30 | (ede-locate-file-in-project loc file) | ||
| 31 | (data-debug-insert-object-slots loc "]")) | ||
| 32 | ) | ||
| 33 | |||
| 34 | (defun ede-locate-test-idutils (file) | ||
| 35 | "Test EDE Locate on FILE using ID Utils type. | ||
| 36 | The search is done with the current EDE root." | ||
| 37 | (interactive "sFile: ") | ||
| 38 | (let ((loc (ede-locate-idutils | ||
| 39 | "test" | ||
| 40 | :root (ede-project-root-directory | ||
| 41 | (ede-toplevel))))) | ||
| 42 | (data-debug-new-buffer "*EDE Locate ADEBUG*") | ||
| 43 | (ede-locate-file-in-project loc file) | ||
| 44 | (data-debug-insert-object-slots loc "]")) | ||
| 45 | ) | ||
| 46 | |||
| 47 | (defun ede-locate-test-cscope (file) | ||
| 48 | "Test EDE Locate on FILE using CScope type. | ||
| 49 | The search is done with the current EDE root." | ||
| 50 | (interactive "sFile: ") | ||
| 51 | (let ((loc (ede-locate-cscope | ||
| 52 | "test" | ||
| 53 | :root (ede-project-root-directory | ||
| 54 | (ede-toplevel))))) | ||
| 55 | (data-debug-new-buffer "*EDE Locate ADEBUG*") | ||
| 56 | (ede-locate-file-in-project loc file) | ||
| 57 | (data-debug-insert-object-slots loc "]")) | ||
| 58 | ) | ||
diff --git a/test/cedet/semantic-ia-utest.el b/test/cedet/semantic-ia-utest.el new file mode 100644 index 00000000000..e5bc0fb65fd --- /dev/null +++ b/test/cedet/semantic-ia-utest.el | |||
| @@ -0,0 +1,509 @@ | |||
| 1 | ;;; semantic-ia-utest.el --- Analyzer unit tests | ||
| 2 | |||
| 3 | ;; Copyright (C) 2008, 2009 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | ;; Author: Eric M. Ludlam <eric@siege-engine.com> | ||
| 6 | |||
| 7 | ;; This file is part of GNU Emacs. | ||
| 8 | |||
| 9 | ;; GNU Emacs is free software: you can redistribute it and/or modify | ||
| 10 | ;; it under the terms of the GNU General Public License as published by | ||
| 11 | ;; the Free Software Foundation, either version 3 of the License, or | ||
| 12 | ;; (at your option) any later version. | ||
| 13 | |||
| 14 | ;; GNU Emacs is distributed in the hope that it will be useful, | ||
| 15 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 16 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 17 | ;; GNU General Public License for more details. | ||
| 18 | |||
| 19 | ;; You should have received a copy of the GNU General Public License | ||
| 20 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | ||
| 21 | |||
| 22 | ;;; Commentary: | ||
| 23 | ;; | ||
| 24 | ;; Use marked-up files in the test directory and run the analyzer | ||
| 25 | ;; on them. Make sure the answers are correct. | ||
| 26 | ;; | ||
| 27 | ;; Each file has cursor keys in them of the form: | ||
| 28 | ;; // -#- ("ans1" "ans2" ) | ||
| 29 | ;; where # is 1, 2, 3, etc, and some sort of answer list. | ||
| 30 | |||
| 31 | ;;; Code: | ||
| 32 | (require 'semantic) | ||
| 33 | (require 'semantic/analyze) | ||
| 34 | (require 'semantic/analyze/refs) | ||
| 35 | (require 'semantic/symref) | ||
| 36 | (require 'semantic/symref/filter) | ||
| 37 | |||
| 38 | (load-file "cedet-utests.el") | ||
| 39 | |||
| 40 | (defvar semantic-ia-utest-file-list | ||
| 41 | '( | ||
| 42 | "tests/testdoublens.cpp" | ||
| 43 | "tests/testsubclass.cpp" | ||
| 44 | "tests/testtypedefs.cpp" | ||
| 45 | "tests/teststruct.cpp" | ||
| 46 | "tests/testtemplates.cpp" | ||
| 47 | "tests/testfriends.cpp" | ||
| 48 | "tests/testusing.cpp" | ||
| 49 | "tests/testnsp.cpp" | ||
| 50 | "tests/testsppcomplete.c" | ||
| 51 | "tests/testvarnames.c" | ||
| 52 | "tests/testjavacomp.java" | ||
| 53 | ) | ||
| 54 | "List of files with analyzer completion test points.") | ||
| 55 | |||
| 56 | (defvar semantic-ia-utest-error-log-list nil | ||
| 57 | "List of errors occuring during a run.") | ||
| 58 | |||
| 59 | ;;;###autoload | ||
| 60 | (defun semantic-ia-utest (&optional arg) | ||
| 61 | "Run the semantic ia unit test against stored sources. | ||
| 62 | Argument ARG specifies which set of tests to run. | ||
| 63 | 1 - ia utests | ||
| 64 | 2 - regs utests | ||
| 65 | 3 - symrefs utests | ||
| 66 | 4 - symref count utests" | ||
| 67 | (interactive "P") | ||
| 68 | (save-excursion | ||
| 69 | |||
| 70 | (let ((fl semantic-ia-utest-file-list) | ||
| 71 | (semantic-ia-utest-error-log-list nil) | ||
| 72 | ) | ||
| 73 | |||
| 74 | (cedet-utest-log-setup "ANALYZER") | ||
| 75 | |||
| 76 | (set-buffer (semantic-find-file-noselect | ||
| 77 | (or (locate-library "semantic-ia-utest.el") | ||
| 78 | "semantic-ia-utest.el"))) | ||
| 79 | |||
| 80 | (while fl | ||
| 81 | |||
| 82 | ;; Make sure we have the files we think we have. | ||
| 83 | (when (not (file-exists-p (car fl))) | ||
| 84 | (error "Cannot find unit test file: %s" (car fl))) | ||
| 85 | |||
| 86 | ;; Run the tests. | ||
| 87 | (let ((fb (find-buffer-visiting (car fl))) | ||
| 88 | (b (semantic-find-file-noselect (car fl) t))) | ||
| 89 | |||
| 90 | ;; Run the test on it. | ||
| 91 | (save-excursion | ||
| 92 | (set-buffer b) | ||
| 93 | |||
| 94 | ;; This line will also force the include, scope, and typecache. | ||
| 95 | (semantic-clear-toplevel-cache) | ||
| 96 | ;; Force tags to be parsed. | ||
| 97 | (semantic-fetch-tags) | ||
| 98 | |||
| 99 | (semantic-ia-utest-log " ** Starting tests in %s" | ||
| 100 | (buffer-name)) | ||
| 101 | |||
| 102 | (when (or (not arg) (= arg 1)) | ||
| 103 | (semantic-ia-utest-buffer)) | ||
| 104 | |||
| 105 | (when (or (not arg) (= arg 2)) | ||
| 106 | (set-buffer b) | ||
| 107 | (semantic-ia-utest-buffer-refs)) | ||
| 108 | |||
| 109 | (when (or (not arg) (= arg 3)) | ||
| 110 | (set-buffer b) | ||
| 111 | (semantic-sr-utest-buffer-refs)) | ||
| 112 | |||
| 113 | (when (or (not arg) (= arg 4)) | ||
| 114 | (set-buffer b) | ||
| 115 | (semantic-src-utest-buffer-refs)) | ||
| 116 | |||
| 117 | (semantic-ia-utest-log " ** Completed tests in %s\n" | ||
| 118 | (buffer-name)) | ||
| 119 | ) | ||
| 120 | |||
| 121 | ;; If it wasn't already in memory, whack it. | ||
| 122 | (when (not fb) | ||
| 123 | (kill-buffer b)) | ||
| 124 | ) | ||
| 125 | (setq fl (cdr fl))) | ||
| 126 | |||
| 127 | (cedet-utest-log-shutdown | ||
| 128 | "ANALYZER" | ||
| 129 | (when semantic-ia-utest-error-log-list | ||
| 130 | (format "%s Failures found." | ||
| 131 | (length semantic-ia-utest-error-log-list)))) | ||
| 132 | (when semantic-ia-utest-error-log-list | ||
| 133 | (error "Failures found during analyzer unit tests")) | ||
| 134 | )) | ||
| 135 | ) | ||
| 136 | |||
| 137 | (defun semantic-ia-utest-buffer () | ||
| 138 | "Run analyzer completion unit-test pass in the current buffer." | ||
| 139 | |||
| 140 | (let* ((idx 1) | ||
| 141 | (regex-p nil) | ||
| 142 | (regex-a nil) | ||
| 143 | (p nil) | ||
| 144 | (a nil) | ||
| 145 | (pass nil) | ||
| 146 | (fail nil) | ||
| 147 | (actual nil) | ||
| 148 | (desired nil) | ||
| 149 | ;; Exclude unpredictable system files in the | ||
| 150 | ;; header include list. | ||
| 151 | (semanticdb-find-default-throttle | ||
| 152 | (remq 'system semanticdb-find-default-throttle)) | ||
| 153 | ) | ||
| 154 | ;; Keep looking for test points until we run out. | ||
| 155 | (while (save-excursion | ||
| 156 | (setq regex-p (concat "//\\s-*-" (number-to-string idx) "-" ) | ||
| 157 | regex-a (concat "//\\s-*#" (number-to-string idx) "#" )) | ||
| 158 | (goto-char (point-min)) | ||
| 159 | (save-match-data | ||
| 160 | (when (re-search-forward regex-p nil t) | ||
| 161 | (setq p (match-beginning 0)))) | ||
| 162 | (save-match-data | ||
| 163 | (when (re-search-forward regex-a nil t) | ||
| 164 | (setq a (match-end 0)))) | ||
| 165 | (and p a)) | ||
| 166 | |||
| 167 | (save-excursion | ||
| 168 | |||
| 169 | (goto-char p) | ||
| 170 | |||
| 171 | (let* ((ctxt (semantic-analyze-current-context)) | ||
| 172 | (acomp | ||
| 173 | (condition-case nil | ||
| 174 | (semantic-analyze-possible-completions ctxt) | ||
| 175 | (error nil)))) | ||
| 176 | (setq actual (mapcar 'semantic-tag-name acomp))) | ||
| 177 | |||
| 178 | (goto-char a) | ||
| 179 | |||
| 180 | (let ((bss (buffer-substring-no-properties (point) (point-at-eol)))) | ||
| 181 | (condition-case nil | ||
| 182 | (setq desired (read bss)) | ||
| 183 | (error (setq desired (format " FAILED TO PARSE: %S" | ||
| 184 | bss))))) | ||
| 185 | |||
| 186 | (if (equal actual desired) | ||
| 187 | (setq pass (cons idx pass)) | ||
| 188 | (setq fail (cons idx fail)) | ||
| 189 | (semantic-ia-utest-log | ||
| 190 | " Failed %d. Desired: %S Actual %S" | ||
| 191 | idx desired actual) | ||
| 192 | (add-to-list 'semantic-ia-utest-error-log-list | ||
| 193 | (list (buffer-name) idx desired actual) | ||
| 194 | ) | ||
| 195 | |||
| 196 | ) | ||
| 197 | ) | ||
| 198 | |||
| 199 | (setq p nil a nil) | ||
| 200 | (setq idx (1+ idx))) | ||
| 201 | |||
| 202 | (if fail | ||
| 203 | (progn | ||
| 204 | (semantic-ia-utest-log | ||
| 205 | " Unit tests (completions) failed tests %S" | ||
| 206 | (reverse fail)) | ||
| 207 | ) | ||
| 208 | (semantic-ia-utest-log " Unit tests (completions) passed (%d total)" | ||
| 209 | (- idx 1))) | ||
| 210 | |||
| 211 | )) | ||
| 212 | |||
| 213 | (defun semantic-ia-utest-buffer-refs () | ||
| 214 | "Run a analyze-refs unit-test pass in the current buffer." | ||
| 215 | |||
| 216 | (let* ((idx 1) | ||
| 217 | (regex-p nil) | ||
| 218 | (p nil) | ||
| 219 | (pass nil) | ||
| 220 | (fail nil) | ||
| 221 | ;; Exclude unpredictable system files in the | ||
| 222 | ;; header include list. | ||
| 223 | (semanticdb-find-default-throttle | ||
| 224 | (remq 'system semanticdb-find-default-throttle)) | ||
| 225 | ) | ||
| 226 | ;; Keep looking for test points until we run out. | ||
| 227 | (while (save-excursion | ||
| 228 | (setq regex-p (concat "//\\s-*\\^" (number-to-string idx) "^" ) | ||
| 229 | ) | ||
| 230 | (goto-char (point-min)) | ||
| 231 | (save-match-data | ||
| 232 | (when (re-search-forward regex-p nil t) | ||
| 233 | (setq p (match-beginning 0)))) | ||
| 234 | p) | ||
| 235 | |||
| 236 | (save-excursion | ||
| 237 | |||
| 238 | (goto-char p) | ||
| 239 | (forward-char -1) | ||
| 240 | |||
| 241 | (let* ((ct (semantic-current-tag)) | ||
| 242 | (refs (semantic-analyze-tag-references ct)) | ||
| 243 | (impl (semantic-analyze-refs-impl refs t)) | ||
| 244 | (proto (semantic-analyze-refs-proto refs t)) | ||
| 245 | (pf nil) | ||
| 246 | ) | ||
| 247 | (setq | ||
| 248 | pf | ||
| 249 | (catch 'failed | ||
| 250 | (if (and impl proto (car impl) (car proto)) | ||
| 251 | (let (ct2 ref2 impl2 proto2 | ||
| 252 | newstart) | ||
| 253 | (cond | ||
| 254 | ((semantic-equivalent-tag-p (car impl) ct) | ||
| 255 | ;; We are on an IMPL. Go To the proto, and find matches. | ||
| 256 | (semantic-go-to-tag (car proto)) | ||
| 257 | (setq newstart (car proto)) | ||
| 258 | ) | ||
| 259 | ((semantic-equivalent-tag-p (car proto) ct) | ||
| 260 | ;; We are on a PROTO. Go to the imple, and find matches | ||
| 261 | (semantic-go-to-tag (car impl)) | ||
| 262 | (setq newstart (car impl)) | ||
| 263 | ) | ||
| 264 | (t | ||
| 265 | ;; No matches is a fail. | ||
| 266 | (throw 'failed t) | ||
| 267 | )) | ||
| 268 | ;; Get the new tag, does it match? | ||
| 269 | (setq ct2 (semantic-current-tag)) | ||
| 270 | |||
| 271 | ;; Does it match? | ||
| 272 | (when (not (semantic-equivalent-tag-p ct2 newstart)) | ||
| 273 | (throw 'failed t)) | ||
| 274 | |||
| 275 | ;; Can we double-jump? | ||
| 276 | (setq ref2 (semantic-analyze-tag-references ct) | ||
| 277 | impl2 (semantic-analyze-refs-impl ref2 t) | ||
| 278 | proto2 (semantic-analyze-refs-proto ref2 t)) | ||
| 279 | |||
| 280 | (when (or (not (and impl2 proto2)) | ||
| 281 | (not | ||
| 282 | (and (semantic-equivalent-tag-p | ||
| 283 | (car impl) (car impl2)) | ||
| 284 | (semantic-equivalent-tag-p | ||
| 285 | (car proto) (car proto2))))) | ||
| 286 | (throw 'failed t)) | ||
| 287 | ) | ||
| 288 | |||
| 289 | ;; Else, no matches at all, so another fail. | ||
| 290 | (throw 'failed t) | ||
| 291 | ))) | ||
| 292 | |||
| 293 | (if (not pf) | ||
| 294 | ;; We passed | ||
| 295 | (setq pass (cons idx pass)) | ||
| 296 | ;; We failed. | ||
| 297 | (setq fail (cons idx fail)) | ||
| 298 | (semantic-ia-utest-log | ||
| 299 | " Failed %d. For %s (Num impls %d) (Num protos %d)" | ||
| 300 | idx (if ct (semantic-tag-name ct) "<No tag found>") | ||
| 301 | (length impl) (length proto)) | ||
| 302 | (add-to-list 'semantic-ia-utest-error-log-list | ||
| 303 | (list (buffer-name) idx) | ||
| 304 | ) | ||
| 305 | )) | ||
| 306 | |||
| 307 | (setq p nil) | ||
| 308 | (setq idx (1+ idx)) | ||
| 309 | |||
| 310 | )) | ||
| 311 | |||
| 312 | (if fail | ||
| 313 | (progn | ||
| 314 | (semantic-ia-utest-log | ||
| 315 | " Unit tests (refs) failed tests") | ||
| 316 | ) | ||
| 317 | (semantic-ia-utest-log " Unit tests (refs) passed (%d total)" | ||
| 318 | (- idx 1))) | ||
| 319 | |||
| 320 | )) | ||
| 321 | |||
| 322 | (defun semantic-sr-utest-buffer-refs () | ||
| 323 | "Run a symref unit-test pass in the current buffer." | ||
| 324 | |||
| 325 | ;; This line will also force the include, scope, and typecache. | ||
| 326 | (semantic-clear-toplevel-cache) | ||
| 327 | ;; Force tags to be parsed. | ||
| 328 | (semantic-fetch-tags) | ||
| 329 | |||
| 330 | (let* ((idx 1) | ||
| 331 | (tag nil) | ||
| 332 | (regex-p nil) | ||
| 333 | (desired nil) | ||
| 334 | (actual-result nil) | ||
| 335 | (actual nil) | ||
| 336 | (pass nil) | ||
| 337 | (fail nil) | ||
| 338 | (symref-tool-used nil) | ||
| 339 | ;; Exclude unpredictable system files in the | ||
| 340 | ;; header include list. | ||
| 341 | (semanticdb-find-default-throttle | ||
| 342 | (remq 'system semanticdb-find-default-throttle)) | ||
| 343 | ) | ||
| 344 | ;; Keep looking for test points until we run out. | ||
| 345 | (while (save-excursion | ||
| 346 | (setq regex-p (concat "//\\s-*\\%" (number-to-string idx) "%" ) | ||
| 347 | ) | ||
| 348 | (goto-char (point-min)) | ||
| 349 | (save-match-data | ||
| 350 | (when (re-search-forward regex-p nil t) | ||
| 351 | (setq tag (semantic-current-tag)) | ||
| 352 | (goto-char (match-end 0)) | ||
| 353 | (setq desired (read (buffer-substring (point) (point-at-eol)))) | ||
| 354 | )) | ||
| 355 | tag) | ||
| 356 | |||
| 357 | (setq actual-result (semantic-symref-find-references-by-name | ||
| 358 | (semantic-tag-name tag) 'target | ||
| 359 | 'symref-tool-used)) | ||
| 360 | |||
| 361 | (if (not actual-result) | ||
| 362 | (progn | ||
| 363 | (setq fail (cons idx fail)) | ||
| 364 | (semantic-ia-utest-log | ||
| 365 | " Failed FNames %d: No results." idx) | ||
| 366 | (semantic-ia-utest-log | ||
| 367 | " Failed Tool: %s" (object-name symref-tool-used)) | ||
| 368 | |||
| 369 | (add-to-list 'semantic-ia-utest-error-log-list | ||
| 370 | (list (buffer-name) idx) | ||
| 371 | ) | ||
| 372 | ) | ||
| 373 | |||
| 374 | (setq actual (list (sort (mapcar | ||
| 375 | 'file-name-nondirectory | ||
| 376 | (semantic-symref-result-get-files actual-result)) | ||
| 377 | 'string<) | ||
| 378 | (sort | ||
| 379 | (mapcar | ||
| 380 | 'semantic-format-tag-canonical-name | ||
| 381 | (semantic-symref-result-get-tags actual-result)) | ||
| 382 | 'string<))) | ||
| 383 | |||
| 384 | |||
| 385 | (if (equal desired actual) | ||
| 386 | ;; We passed | ||
| 387 | (setq pass (cons idx pass)) | ||
| 388 | ;; We failed. | ||
| 389 | (setq fail (cons idx fail)) | ||
| 390 | (when (not (equal (car actual) (car desired))) | ||
| 391 | (semantic-ia-utest-log | ||
| 392 | " Failed FNames %d: Actual: %S Desired: %S" | ||
| 393 | idx (car actual) (car desired)) | ||
| 394 | (semantic-ia-utest-log | ||
| 395 | " Failed Tool: %s" (object-name symref-tool-used)) | ||
| 396 | ) | ||
| 397 | (when (not (equal (car (cdr actual)) (car (cdr desired)))) | ||
| 398 | (semantic-ia-utest-log | ||
| 399 | " Failed TNames %d: Actual: %S Desired: %S" | ||
| 400 | idx (car (cdr actual)) (car (cdr desired))) | ||
| 401 | (semantic-ia-utest-log | ||
| 402 | " Failed Tool: %s" (object-name symref-tool-used)) | ||
| 403 | ) | ||
| 404 | (add-to-list 'semantic-ia-utest-error-log-list | ||
| 405 | (list (buffer-name) idx) | ||
| 406 | ) | ||
| 407 | )) | ||
| 408 | |||
| 409 | (setq idx (1+ idx)) | ||
| 410 | (setq tag nil)) | ||
| 411 | |||
| 412 | (if fail | ||
| 413 | (progn | ||
| 414 | (semantic-ia-utest-log | ||
| 415 | " Unit tests (symrefs) failed tests") | ||
| 416 | ) | ||
| 417 | (semantic-ia-utest-log " Unit tests (symrefs) passed (%d total)" | ||
| 418 | (- idx 1))) | ||
| 419 | |||
| 420 | )) | ||
| 421 | |||
| 422 | (defun semantic-src-utest-buffer-refs () | ||
| 423 | "Run a sym-ref counting unit-test pass in the current buffer." | ||
| 424 | |||
| 425 | ;; This line will also force the include, scope, and typecache. | ||
| 426 | (semantic-clear-toplevel-cache) | ||
| 427 | ;; Force tags to be parsed. | ||
| 428 | (semantic-fetch-tags) | ||
| 429 | |||
| 430 | (let* ((idx 1) | ||
| 431 | (start nil) | ||
| 432 | (regex-p nil) | ||
| 433 | (desired nil) | ||
| 434 | (actual nil) | ||
| 435 | (pass nil) | ||
| 436 | (fail nil) | ||
| 437 | ;; Exclude unpredictable system files in the | ||
| 438 | ;; header include list. | ||
| 439 | (semanticdb-find-default-throttle | ||
| 440 | (remq 'system semanticdb-find-default-throttle)) | ||
| 441 | ) | ||
| 442 | ;; Keep looking for test points until we run out. | ||
| 443 | (while (save-excursion | ||
| 444 | (setq regex-p (concat "//\\s-*@" | ||
| 445 | (number-to-string idx) | ||
| 446 | "@\\s-+\\(\\w+\\)" )) | ||
| 447 | (goto-char (point-min)) | ||
| 448 | (save-match-data | ||
| 449 | (when (re-search-forward regex-p nil t) | ||
| 450 | (goto-char (match-beginning 1)) | ||
| 451 | (setq desired (read (buffer-substring (point) (point-at-eol)))) | ||
| 452 | (setq start (match-beginning 0)) | ||
| 453 | (goto-char start) | ||
| 454 | (setq actual (semantic-symref-test-count-hits-in-tag)) | ||
| 455 | start))) | ||
| 456 | |||
| 457 | (if (not actual) | ||
| 458 | (progn | ||
| 459 | (setq fail (cons idx fail)) | ||
| 460 | (semantic-ia-utest-log | ||
| 461 | " Failed symref count %d: No results." idx) | ||
| 462 | |||
| 463 | (add-to-list 'semantic-ia-utest-error-log-list | ||
| 464 | (list (buffer-name) idx) | ||
| 465 | ) | ||
| 466 | ) | ||
| 467 | |||
| 468 | (if (equal desired actual) | ||
| 469 | ;; We passed | ||
| 470 | (setq pass (cons idx pass)) | ||
| 471 | ;; We failed. | ||
| 472 | (setq fail (cons idx fail)) | ||
| 473 | (when (not (equal actual desired)) | ||
| 474 | (semantic-ia-utest-log | ||
| 475 | " Failed symref count %d: Actual: %S Desired: %S" | ||
| 476 | idx actual desired) | ||
| 477 | ) | ||
| 478 | |||
| 479 | (add-to-list 'semantic-ia-utest-error-log-list | ||
| 480 | (list (buffer-name) idx) | ||
| 481 | ) | ||
| 482 | )) | ||
| 483 | |||
| 484 | (setq idx (1+ idx)) | ||
| 485 | ) | ||
| 486 | |||
| 487 | (if fail | ||
| 488 | (progn | ||
| 489 | (semantic-ia-utest-log | ||
| 490 | " Unit tests (symrefs counter) failed tests") | ||
| 491 | ) | ||
| 492 | (semantic-ia-utest-log " Unit tests (symrefs counter) passed (%d total)" | ||
| 493 | (- idx 1))) | ||
| 494 | |||
| 495 | )) | ||
| 496 | |||
| 497 | (defun semantic-ia-utest-start-log () | ||
| 498 | "Start up a testlog for a run." | ||
| 499 | ;; Redo w/ CEDET utest framework. | ||
| 500 | (cedet-utest-log-start "semantic: analyzer tests")) | ||
| 501 | |||
| 502 | (defun semantic-ia-utest-log (&rest args) | ||
| 503 | "Log some test results. | ||
| 504 | Pass ARGS to format to create the log message." | ||
| 505 | ;; Forward to CEDET utest framework. | ||
| 506 | (apply 'cedet-utest-log args)) | ||
| 507 | |||
| 508 | (provide 'semantic-ia-utest) | ||
| 509 | ;;; semantic-ia-utest.el ends here | ||
diff --git a/test/cedet/semantic-tests.el b/test/cedet/semantic-tests.el new file mode 100644 index 00000000000..1cf23f66090 --- /dev/null +++ b/test/cedet/semantic-tests.el | |||
| @@ -0,0 +1,436 @@ | |||
| 1 | ;;; semantic-utest.el --- Miscellaneous Semantic tests. | ||
| 2 | |||
| 3 | ;;; Copyright (C) 2003, 2004, 2007, 2008, 2009 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | ;; Author: Eric M. Ludlam <zappo@gnu.org> | ||
| 6 | |||
| 7 | ;; This file is part of GNU Emacs. | ||
| 8 | |||
| 9 | ;; GNU Emacs is free software: you can redistribute it and/or modify | ||
| 10 | ;; it under the terms of the GNU General Public License as published by | ||
| 11 | ;; the Free Software Foundation, either version 3 of the License, or | ||
| 12 | ;; (at your option) any later version. | ||
| 13 | |||
| 14 | ;; GNU Emacs is distributed in the hope that it will be useful, | ||
| 15 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 16 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 17 | ;; GNU General Public License for more details. | ||
| 18 | |||
| 19 | ;; You should have received a copy of the GNU General Public License | ||
| 20 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | ||
| 21 | |||
| 22 | ;;; Commentary: | ||
| 23 | |||
| 24 | ;; Originally, there are many test functions scattered among the | ||
| 25 | ;; Semantic source files. This file consolidates them. | ||
| 26 | |||
| 27 | (require 'data-debug) | ||
| 28 | |||
| 29 | ;;; From semantic-complete | ||
| 30 | |||
| 31 | (require 'semantic/complete) | ||
| 32 | |||
| 33 | (defun semantic-complete-test () | ||
| 34 | "Test completion mechanisms." | ||
| 35 | (interactive) | ||
| 36 | (message "%S" | ||
| 37 | (semantic-format-tag-prototype | ||
| 38 | (semantic-complete-read-tag-project "Symbol: ")))) | ||
| 39 | |||
| 40 | ;;; From semanticdb-ebrowse | ||
| 41 | |||
| 42 | (require 'semantic/db-ebrowse) | ||
| 43 | |||
| 44 | (defun semanticdb-ebrowse-run-tests () | ||
| 45 | "Run some tests of the semanticdb-ebrowse system. | ||
| 46 | All systems are different. Ask questions along the way." | ||
| 47 | (interactive) | ||
| 48 | (let ((doload nil)) | ||
| 49 | (when (y-or-n-p "Create a system database to test with? ") | ||
| 50 | (call-interactively 'semanticdb-create-ebrowse-database) | ||
| 51 | (setq doload t)) | ||
| 52 | ;; Should we load in caches | ||
| 53 | (when (if doload | ||
| 54 | (y-or-n-p "New database created. Reload system databases? ") | ||
| 55 | (y-or-n-p "Load in all system databases? ")) | ||
| 56 | (semanticdb-load-ebrowse-caches))) | ||
| 57 | ;; Ok, databases were creatd. Lets try some searching. | ||
| 58 | (when (not (or (eq major-mode 'c-mode) | ||
| 59 | (eq major-mode 'c++-mode))) | ||
| 60 | (error "Please make your default buffer be a C or C++ file, then | ||
| 61 | run the test again.."))) | ||
| 62 | |||
| 63 | (defun semanticdb-ebrowse-dump () | ||
| 64 | "Find the first loaded ebrowse table, and dump out the contents." | ||
| 65 | (interactive) | ||
| 66 | (let ((db semanticdb-database-list) | ||
| 67 | (ab nil)) | ||
| 68 | (while db | ||
| 69 | (when (semanticdb-project-database-ebrowse-p (car db)) | ||
| 70 | (setq ab (data-debug-new-buffer "*EBROWSE Database*")) | ||
| 71 | (data-debug-insert-thing (car db) "*" "") | ||
| 72 | (setq db nil) | ||
| 73 | ) | ||
| 74 | (setq db (cdr db))))) | ||
| 75 | |||
| 76 | ;;; From semanticdb-global: | ||
| 77 | |||
| 78 | (require 'semantic/db-global) | ||
| 79 | |||
| 80 | (defvar semanticdb-test-gnu-global-startfile "~/src/global-5.7.3/global/global.c" | ||
| 81 | "File to use for testing.") | ||
| 82 | |||
| 83 | (defun semanticdb-test-gnu-global (searchfor &optional standardfile) | ||
| 84 | "Test the GNU Global semanticdb. | ||
| 85 | Argument SEARCHFOR is the text to search for. | ||
| 86 | If optional arg STANDARDFILE is non nil, use a standard file w/ global enabled." | ||
| 87 | (interactive "sSearch For Tag: \nP") | ||
| 88 | |||
| 89 | (require 'data-debug) | ||
| 90 | (save-excursion | ||
| 91 | (when standardfile | ||
| 92 | (save-match-data | ||
| 93 | (set-buffer (find-file-noselect semanticdb-test-gnu-global-startfile)))) | ||
| 94 | |||
| 95 | (condition-case err | ||
| 96 | (semanticdb-enable-gnu-global-in-buffer) | ||
| 97 | (error (if standardfile | ||
| 98 | (error err) | ||
| 99 | (save-match-data | ||
| 100 | (set-buffer (find-file-noselect semanticdb-test-gnu-global-startfile))) | ||
| 101 | (semanticdb-enable-gnu-global-in-buffer)))) | ||
| 102 | |||
| 103 | (let* ((db (semanticdb-project-database-global "global")) | ||
| 104 | (tab (semanticdb-file-table db (buffer-file-name))) | ||
| 105 | (result (semanticdb-deep-find-tags-for-completion-method tab searchfor)) | ||
| 106 | ) | ||
| 107 | (data-debug-new-buffer "*SemanticDB Gnu Global Result*") | ||
| 108 | (data-debug-insert-thing result "?" "")))) | ||
| 109 | |||
| 110 | ;;; From semantic-find | ||
| 111 | |||
| 112 | (require 'semantic/find) | ||
| 113 | |||
| 114 | (defun semantic-find-benchmark () | ||
| 115 | "Run some simple benchmarks to see how we are doing. | ||
| 116 | Optional argument ARG is the number of iterations to run." | ||
| 117 | (interactive) | ||
| 118 | (require 'benchmark) | ||
| 119 | (let ((f-name nil) | ||
| 120 | (b-name nil) | ||
| 121 | (f-comp) | ||
| 122 | (b-comp) | ||
| 123 | (f-regex) | ||
| 124 | ) | ||
| 125 | (garbage-collect) | ||
| 126 | (setq f-name | ||
| 127 | (benchmark-run-compiled | ||
| 128 | 1000 (semantic-find-first-tag-by-name "class3" | ||
| 129 | "test/test.cpp"))) | ||
| 130 | (garbage-collect) | ||
| 131 | (setq b-name | ||
| 132 | (benchmark-run-compiled | ||
| 133 | 1000 (semantic-brute-find-first-tag-by-name "class3" | ||
| 134 | "test/test.cpp"))) | ||
| 135 | (garbage-collect) | ||
| 136 | (setq f-comp | ||
| 137 | (benchmark-run-compiled | ||
| 138 | 1000 (semantic-find-tags-for-completion "method" | ||
| 139 | "test/test.cpp"))) | ||
| 140 | (garbage-collect) | ||
| 141 | (setq b-comp | ||
| 142 | (benchmark-run-compiled | ||
| 143 | 1000 (semantic-brute-find-tag-by-name-regexp "^method" | ||
| 144 | "test/test.cpp"))) | ||
| 145 | (garbage-collect) | ||
| 146 | (setq f-regex | ||
| 147 | (benchmark-run-compiled | ||
| 148 | 1000 (semantic-find-tags-by-name-regexp "^method" | ||
| 149 | "test/test.cpp"))) | ||
| 150 | |||
| 151 | (message "Name [new old] [ %.3f %.3f ] Complete [newc/new old] [ %.3f/%.3f %.3f ]" | ||
| 152 | (car f-name) (car b-name) | ||
| 153 | (car f-comp) (car f-regex) | ||
| 154 | (car b-comp)) | ||
| 155 | )) | ||
| 156 | |||
| 157 | ;;; From semantic-format | ||
| 158 | |||
| 159 | (require 'semantic/format) | ||
| 160 | |||
| 161 | (defun semantic-test-all-format-tag-functions (&optional arg) | ||
| 162 | "Test all outputs from `semantic-format-tag-functions'. | ||
| 163 | Output is generated from the function under `point'. | ||
| 164 | Optional argument ARG specifies not to use color." | ||
| 165 | (interactive "P") | ||
| 166 | (semantic-fetch-tags) | ||
| 167 | (let* ((tag (semantic-current-tag)) | ||
| 168 | (par (semantic-current-tag-parent)) | ||
| 169 | (fns semantic-format-tag-functions)) | ||
| 170 | (with-output-to-temp-buffer "*format-tag*" | ||
| 171 | (princ "Tag->format function tests:") | ||
| 172 | (while fns | ||
| 173 | (princ "\n") | ||
| 174 | (princ (car fns)) | ||
| 175 | (princ ":\n ") | ||
| 176 | (let ((s (funcall (car fns) tag par (not arg)))) | ||
| 177 | (save-excursion | ||
| 178 | (set-buffer "*format-tag*") | ||
| 179 | (goto-char (point-max)) | ||
| 180 | (insert s))) | ||
| 181 | (setq fns (cdr fns)))) | ||
| 182 | )) | ||
| 183 | |||
| 184 | ;;; From semantic-fw: | ||
| 185 | |||
| 186 | (require 'semantic/fw) | ||
| 187 | |||
| 188 | (defun semantic-test-data-cache () | ||
| 189 | "Test the data cache." | ||
| 190 | (interactive) | ||
| 191 | (let ((data '(a b c))) | ||
| 192 | (save-excursion | ||
| 193 | (set-buffer (get-buffer-create " *semantic-test-data-cache*")) | ||
| 194 | (erase-buffer) | ||
| 195 | (insert "The Moose is Loose") | ||
| 196 | (goto-char (point-min)) | ||
| 197 | (semantic-cache-data-to-buffer (current-buffer) (point) (+ (point) 5) | ||
| 198 | data 'moose 'exit-cache-zone) | ||
| 199 | (if (equal (semantic-get-cache-data 'moose) data) | ||
| 200 | (message "Successfully retrieved cached data.") | ||
| 201 | (error "Failed to retrieve cached data"))))) | ||
| 202 | |||
| 203 | (defun semantic-test-throw-on-input () | ||
| 204 | "Test that throw on input will work." | ||
| 205 | (interactive) | ||
| 206 | (semantic-throw-on-input 'done-die) | ||
| 207 | (message "Exit Code: %s" | ||
| 208 | (semantic-exit-on-input 'testing | ||
| 209 | (let ((inhibit-quit nil) | ||
| 210 | (message-log-max nil)) | ||
| 211 | (while t | ||
| 212 | (message "Looping ... press a key to test") | ||
| 213 | (semantic-throw-on-input 'test-inner-loop)) | ||
| 214 | 'exit))) | ||
| 215 | (when (input-pending-p) | ||
| 216 | (if (fboundp 'read-event) | ||
| 217 | (read-event) | ||
| 218 | (read-char)))) | ||
| 219 | |||
| 220 | ;;; From semantic-idle: | ||
| 221 | |||
| 222 | (require 'semantic/idle) | ||
| 223 | |||
| 224 | (defun semantic-idle-pnf-test () | ||
| 225 | "Test `semantic-idle-scheduler-work-parse-neighboring-files' and time it." | ||
| 226 | (interactive) | ||
| 227 | (let ((start (current-time)) | ||
| 228 | (junk (semantic-idle-scheduler-work-parse-neighboring-files)) | ||
| 229 | (end (current-time))) | ||
| 230 | (message "Work took %.2f seconds." (semantic-elapsed-time start end)))) | ||
| 231 | |||
| 232 | ;;; From semantic-lex: | ||
| 233 | |||
| 234 | (require 'semantic/lex) | ||
| 235 | |||
| 236 | (defun semantic-lex-test-full-depth (arg) | ||
| 237 | "Test the semantic lexer in the current buffer parsing through lists. | ||
| 238 | Usually the lexer parses | ||
| 239 | If universal argument ARG, then try the whole buffer." | ||
| 240 | (interactive "P") | ||
| 241 | (let* ((start (current-time)) | ||
| 242 | (result (semantic-lex | ||
| 243 | (if arg (point-min) (point)) | ||
| 244 | (point-max) | ||
| 245 | 100)) | ||
| 246 | (end (current-time))) | ||
| 247 | (message "Elapsed Time: %.2f seconds." | ||
| 248 | (semantic-elapsed-time start end)) | ||
| 249 | (pop-to-buffer "*Lexer Output*") | ||
| 250 | (require 'pp) | ||
| 251 | (erase-buffer) | ||
| 252 | (insert (pp-to-string result)) | ||
| 253 | (goto-char (point-min)))) | ||
| 254 | |||
| 255 | (defun semantic-lex-test-region (beg end) | ||
| 256 | "Test the semantic lexer in the current buffer. | ||
| 257 | Analyze the area between BEG and END." | ||
| 258 | (interactive "r") | ||
| 259 | (let ((result (semantic-lex beg end))) | ||
| 260 | (pop-to-buffer "*Lexer Output*") | ||
| 261 | (require 'pp) | ||
| 262 | (erase-buffer) | ||
| 263 | (insert (pp-to-string result)) | ||
| 264 | (goto-char (point-min)))) | ||
| 265 | |||
| 266 | ;;; From semantic-lex-spp: | ||
| 267 | |||
| 268 | (require 'semantic/lex-spp) | ||
| 269 | |||
| 270 | (defun semantic-lex-spp-write-test () | ||
| 271 | "Test the semantic tag writer against the current buffer." | ||
| 272 | (interactive) | ||
| 273 | (with-output-to-temp-buffer "*SPP Write Test*" | ||
| 274 | (semantic-lex-spp-table-write-slot-value | ||
| 275 | (semantic-lex-spp-save-table)))) | ||
| 276 | |||
| 277 | (defun semantic-lex-spp-write-utest () | ||
| 278 | "Unit test using the test spp file to test the slot write fcn." | ||
| 279 | (interactive) | ||
| 280 | (let* ((sem (locate-library "semantic-lex-spp.el")) | ||
| 281 | (dir (file-name-directory sem))) | ||
| 282 | (save-excursion | ||
| 283 | (set-buffer (find-file-noselect | ||
| 284 | (expand-file-name "tests/testsppreplace.c" | ||
| 285 | dir))) | ||
| 286 | (semantic-lex-spp-write-test)))) | ||
| 287 | |||
| 288 | ;;; From semantic-tag-write: | ||
| 289 | |||
| 290 | ;;; TESTING. | ||
| 291 | |||
| 292 | (require 'semantic/tag-write) | ||
| 293 | |||
| 294 | (defun semantic-tag-write-test () | ||
| 295 | "Test the semantic tag writer against the tag under point." | ||
| 296 | (interactive) | ||
| 297 | (with-output-to-temp-buffer "*Tag Write Test*" | ||
| 298 | (semantic-tag-write-one-tag (semantic-current-tag)))) | ||
| 299 | |||
| 300 | (defun semantic-tag-write-list-test () | ||
| 301 | "Test the semantic tag writer against the tag under point." | ||
| 302 | (interactive) | ||
| 303 | (with-output-to-temp-buffer "*Tag Write Test*" | ||
| 304 | (semantic-tag-write-tag-list (semantic-fetch-tags)))) | ||
| 305 | |||
| 306 | ;;; From semantic-symref-filter: | ||
| 307 | |||
| 308 | (require 'semantic/symref/filter) | ||
| 309 | |||
| 310 | (defun semantic-symref-test-count-hits-in-tag () | ||
| 311 | "Lookup in the current tag the symbol under point. | ||
| 312 | the count all the other references to the same symbol within the | ||
| 313 | tag that contains point, and return that." | ||
| 314 | (interactive) | ||
| 315 | (let* ((ctxt (semantic-analyze-current-context)) | ||
| 316 | (target (car (reverse (oref ctxt prefix)))) | ||
| 317 | (tag (semantic-current-tag)) | ||
| 318 | (start (current-time)) | ||
| 319 | (Lcount 0)) | ||
| 320 | (when (semantic-tag-p target) | ||
| 321 | (semantic-symref-hits-in-region | ||
| 322 | target (lambda (start end prefix) (setq Lcount (1+ Lcount))) | ||
| 323 | (semantic-tag-start tag) | ||
| 324 | (semantic-tag-end tag)) | ||
| 325 | (when (interactive-p) | ||
| 326 | (message "Found %d occurances of %s in %.2f seconds" | ||
| 327 | Lcount (semantic-tag-name target) | ||
| 328 | (semantic-elapsed-time start (current-time)))) | ||
| 329 | Lcount))) | ||
| 330 | |||
| 331 | ;;; From bovine-gcc: | ||
| 332 | |||
| 333 | (require 'semantic/bovine/gcc) | ||
| 334 | |||
| 335 | ;; Example output of "gcc -v" | ||
| 336 | (defvar semantic-gcc-test-strings | ||
| 337 | '(;; My old box: | ||
| 338 | "Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.2.2/specs | ||
| 339 | Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --host=i386-redhat-linux | ||
| 340 | Thread model: posix | ||
| 341 | gcc version 3.2.2 20030222 (Red Hat Linux 3.2.2-5)" | ||
| 342 | ;; Alex Ott: | ||
| 343 | "Using built-in specs. | ||
| 344 | Target: i486-linux-gnu | ||
| 345 | Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.3.1-9ubuntu1' --with-bugurl=file:///usr/share/doc/gcc-4.3/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.3 --program-suffix=-4.3 --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-mpfr --enable-targets=all --enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu | ||
| 346 | Thread model: posix | ||
| 347 | gcc version 4.3.1 (Ubuntu 4.3.1-9ubuntu1)" | ||
| 348 | ;; My debian box: | ||
| 349 | "Using built-in specs. | ||
| 350 | Target: x86_64-unknown-linux-gnu | ||
| 351 | Configured with: ../../../sources/gcc/configure --prefix=/usr/local/glibc-2.3.6/x86_64/apps/gcc-4.2.3 --with-gmp=/usr/local/gcc/gmp --with-mpfr=/usr/local/gcc/mpfr --enable-languages=c,c++,fortran --with-as=/usr/local/glibc-2.3.6/x86_64/apps/gcc-4.2.3/bin/as --with-ld=/usr/local/glibc-2.3.6/x86_64/apps/gcc-4.2.3/bin/ld --disable-multilib | ||
| 352 | Thread model: posix | ||
| 353 | gcc version 4.2.3" | ||
| 354 | ;; My mac: | ||
| 355 | "Using built-in specs. | ||
| 356 | Target: i686-apple-darwin8 | ||
| 357 | Configured with: /private/var/tmp/gcc/gcc-5341.obj~1/src/configure --disable-checking -enable-werror --prefix=/usr --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-transform-name=/^[cg][^.-]*$/s/$/-4.0/ --with-gxx-include-dir=/include/c++/4.0.0 --with-slibdir=/usr/lib --build=powerpc-apple-darwin8 --with-arch=pentium-m --with-tune=prescott --program-prefix= --host=i686-apple-darwin8 --target=i686-apple-darwin8 | ||
| 358 | Thread model: posix | ||
| 359 | gcc version 4.0.1 (Apple Computer, Inc. build 5341)" | ||
| 360 | ;; Ubuntu Intrepid | ||
| 361 | "Using built-in specs. | ||
| 362 | Target: x86_64-linux-gnu | ||
| 363 | Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.3.2-1ubuntu12' --with-bugurl=file:///usr/share/doc/gcc-4.3/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.3 --program-suffix=-4.3 --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-mpfr --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu | ||
| 364 | Thread model: posix | ||
| 365 | gcc version 4.3.2 (Ubuntu 4.3.2-1ubuntu12)" | ||
| 366 | ;; Red Hat EL4 | ||
| 367 | "Reading specs from /usr/lib/gcc/x86_64-redhat-linux/3.4.6/specs | ||
| 368 | Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-java-awt=gtk --host=x86_64-redhat-linux | ||
| 369 | Thread model: posix | ||
| 370 | gcc version 3.4.6 20060404 (Red Hat 3.4.6-10)" | ||
| 371 | ;; Red Hat EL5 | ||
| 372 | "Using built-in specs. | ||
| 373 | Target: x86_64-redhat-linux | ||
| 374 | Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-libgcj-multifile --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --enable-plugin --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre --with-cpu=generic --host=x86_64-redhat-linux | ||
| 375 | Thread model: posix | ||
| 376 | gcc version 4.1.2 20080704 (Red Hat 4.1.2-44)" | ||
| 377 | ;; David Engster's german gcc on ubuntu 4.3 | ||
| 378 | "Es werden eingebaute Spezifikationen verwendet. | ||
| 379 | Ziel: i486-linux-gnu | ||
| 380 | Konfiguriert mit: ../src/configure -v --with-pkgversion='Ubuntu 4.3.2-1ubuntu12' --with-bugurl=file:///usr/share/doc/gcc-4.3/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.3 --program-suffix=-4.3 --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-mpfr --enable-targets=all --enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu | ||
| 381 | Thread-Modell: posix | ||
| 382 | gcc-Version 4.3.2 (Ubuntu 4.3.2-1ubuntu12)" | ||
| 383 | ;; Damien Deville bsd | ||
| 384 | "Using built-in specs. | ||
| 385 | Target: i386-undermydesk-freebsd | ||
| 386 | Configured with: FreeBSD/i386 system compiler | ||
| 387 | Thread model: posix | ||
| 388 | gcc version 4.2.1 20070719 [FreeBSD]" | ||
| 389 | ) | ||
| 390 | "A bunch of sample gcc -v outputs from different machines.") | ||
| 391 | |||
| 392 | (defvar semantic-gcc-test-strings-fail | ||
| 393 | '(;; A really old solaris box I found | ||
| 394 | "Reading specs from /usr/local/gcc-2.95.2/lib/gcc-lib/sparc-sun-solaris2.6/2.95.2/specs | ||
| 395 | gcc version 2.95.2 19991024 (release)" | ||
| 396 | ) | ||
| 397 | "A bunch of sample gcc -v outputs that fail to provide the info we want.") | ||
| 398 | |||
| 399 | (defun semantic-gcc-test-output-parser () | ||
| 400 | "Test the output parser against some collected strings." | ||
| 401 | (interactive) | ||
| 402 | (let ((fail nil)) | ||
| 403 | (dolist (S semantic-gcc-test-strings) | ||
| 404 | (let* ((fields (semantic-gcc-fields S)) | ||
| 405 | (v (cdr (assoc 'version fields))) | ||
| 406 | (h (or (cdr (assoc 'target fields)) | ||
| 407 | (cdr (assoc '--target fields)) | ||
| 408 | (cdr (assoc '--host fields)))) | ||
| 409 | (p (cdr (assoc '--prefix fields))) | ||
| 410 | ) | ||
| 411 | ;; No longer test for prefixes. | ||
| 412 | (when (not (and v h)) | ||
| 413 | (let ((strs (split-string S "\n"))) | ||
| 414 | (message "Test failed on %S\nV H P:\n%S %S %S" (car strs) v h p)) | ||
| 415 | (setq fail t)) | ||
| 416 | )) | ||
| 417 | (dolist (S semantic-gcc-test-strings-fail) | ||
| 418 | (let* ((fields (semantic-gcc-fields S)) | ||
| 419 | (v (cdr (assoc 'version fields))) | ||
| 420 | (h (or (cdr (assoc '--host fields)) | ||
| 421 | (cdr (assoc 'target fields)))) | ||
| 422 | (p (cdr (assoc '--prefix fields))) | ||
| 423 | ) | ||
| 424 | (when (and v h p) | ||
| 425 | (message "Negative test failed on %S" S) | ||
| 426 | (setq fail t)) | ||
| 427 | )) | ||
| 428 | (if (not fail) (message "Tests passed.")) | ||
| 429 | )) | ||
| 430 | |||
| 431 | (defun semantic-gcc-test-output-parser-this-machine () | ||
| 432 | "Test the output parser against the machine currently running Emacs." | ||
| 433 | (interactive) | ||
| 434 | (let ((semantic-gcc-test-strings (list (semantic-gcc-query "gcc" "-v")))) | ||
| 435 | (semantic-gcc-test-output-parser)) | ||
| 436 | ) | ||
diff --git a/test/cedet/semantic-utest-c.el b/test/cedet/semantic-utest-c.el new file mode 100644 index 00000000000..cd9d0a2a5e5 --- /dev/null +++ b/test/cedet/semantic-utest-c.el | |||
| @@ -0,0 +1,72 @@ | |||
| 1 | ;;; semantic-utest-c.el --- C based parsing tests. | ||
| 2 | |||
| 3 | ;; Copyright (C) 2008, 2009 Eric M. Ludlam | ||
| 4 | |||
| 5 | ;; Author: Eric M. Ludlam <eric@siege-engine.com> | ||
| 6 | ;; X-RCS: $Id: semantic-utest-c.el,v 1.1.2.1 2009/09/20 04:00:16 cyd Exp $ | ||
| 7 | |||
| 8 | ;; This program is free software; you can redistribute it and/or | ||
| 9 | ;; modify it under the terms of the GNU General Public License as | ||
| 10 | ;; published by the Free Software Foundation; either version 2, or (at | ||
| 11 | ;; your option) any later version. | ||
| 12 | |||
| 13 | ;; This program is distributed in the hope that it will be useful, but | ||
| 14 | ;; WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 15 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 16 | ;; General Public License for more details. | ||
| 17 | |||
| 18 | ;; You should have received a copy of the GNU General Public License | ||
| 19 | ;; along with this program; see the file COPYING. If not, write to | ||
| 20 | ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
| 21 | ;; Boston, MA 02110-1301, USA. | ||
| 22 | |||
| 23 | ;;; Commentary: | ||
| 24 | ;; | ||
| 25 | ;; Run some C based parsing tests. | ||
| 26 | |||
| 27 | (require 'semantic) | ||
| 28 | |||
| 29 | (defvar semantic-utest-c-comparisons | ||
| 30 | '( ("testsppreplace.c" . "testsppreplaced.c") | ||
| 31 | ) | ||
| 32 | "List of files to parse and compare against eachother.") | ||
| 33 | |||
| 34 | ;;; Code: | ||
| 35 | ;;;###autoload | ||
| 36 | (defun semantic-utest-c () | ||
| 37 | "Run parsing test for C from the test directory." | ||
| 38 | (interactive) | ||
| 39 | (dolist (fp semantic-utest-c-comparisons) | ||
| 40 | (let* ((sem (locate-library "semantic")) | ||
| 41 | (sdir (file-name-directory sem)) | ||
| 42 | (semantic-lex-c-nested-namespace-ignore-second nil) | ||
| 43 | (tags-actual | ||
| 44 | (save-excursion | ||
| 45 | (set-buffer (find-file-noselect (expand-file-name (concat "tests/" (car fp)) sdir))) | ||
| 46 | (semantic-clear-toplevel-cache) | ||
| 47 | (semantic-fetch-tags))) | ||
| 48 | (tags-expected | ||
| 49 | (save-excursion | ||
| 50 | (set-buffer (find-file-noselect (expand-file-name (concat "tests/" (cdr fp)) sdir))) | ||
| 51 | (semantic-clear-toplevel-cache) | ||
| 52 | (semantic-fetch-tags)))) | ||
| 53 | ;; Now that we have the tags, compare them for SPP accuracy. | ||
| 54 | (dolist (tag tags-actual) | ||
| 55 | (if (and (semantic-tag-of-class-p tag 'variable) | ||
| 56 | (semantic-tag-variable-constant-p tag)) | ||
| 57 | nil ; skip the macros. | ||
| 58 | (if (semantic-tag-similar-with-subtags-p tag (car tags-expected)) | ||
| 59 | (setq tags-expected (cdr tags-expected)) | ||
| 60 | (with-mode-local c-mode | ||
| 61 | (error "Found: >> %s << Expected: >> %s <<" | ||
| 62 | (semantic-format-tag-prototype tag nil t) | ||
| 63 | (semantic-format-tag-prototype (car tags-expected) nil t) | ||
| 64 | ))) | ||
| 65 | )) | ||
| 66 | ;; Passed? | ||
| 67 | (message "PASSED!") | ||
| 68 | ))) | ||
| 69 | |||
| 70 | |||
| 71 | (provide 'semantic-utest-c) | ||
| 72 | ;;; semantic-utest-c.el ends here | ||
diff --git a/test/cedet/semantic-utest.el b/test/cedet/semantic-utest.el new file mode 100644 index 00000000000..51d1341245f --- /dev/null +++ b/test/cedet/semantic-utest.el | |||
| @@ -0,0 +1,867 @@ | |||
| 1 | ;;; semantic-utest.el --- Tests for semantic's parsing system. | ||
| 2 | |||
| 3 | ;;; Copyright (C) 2003, 2004, 2007, 2008, 2009 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | ;; Author: Eric M. Ludlam <zappo@gnu.org> | ||
| 6 | |||
| 7 | ;; This file is part of GNU Emacs. | ||
| 8 | |||
| 9 | ;; GNU Emacs is free software: you can redistribute it and/or modify | ||
| 10 | ;; it under the terms of the GNU General Public License as published by | ||
| 11 | ;; the Free Software Foundation, either version 3 of the License, or | ||
| 12 | ;; (at your option) any later version. | ||
| 13 | |||
| 14 | ;; GNU Emacs is distributed in the hope that it will be useful, | ||
| 15 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 16 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 17 | ;; GNU General Public License for more details. | ||
| 18 | |||
| 19 | ;; You should have received a copy of the GNU General Public License | ||
| 20 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | ||
| 21 | |||
| 22 | ;;; Commentary: | ||
| 23 | ;; | ||
| 24 | ;; Semantic's parsing and partial parsing system is pretty complex. | ||
| 25 | ;; These unit tests attempt to emulate semantic's partial reparsing | ||
| 26 | ;; and full reparsing system, and anything else I may feel the urge | ||
| 27 | ;; to write a test for. | ||
| 28 | |||
| 29 | (require 'semantic) | ||
| 30 | |||
| 31 | (load-file "cedet-utests.el") | ||
| 32 | |||
| 33 | (defvar semantic-utest-temp-directory (if (fboundp 'temp-directory) | ||
| 34 | (temp-directory) | ||
| 35 | temporary-file-directory) | ||
| 36 | "Temporary directory to use when creating files.") | ||
| 37 | |||
| 38 | (defun semantic-utest-fname (name) | ||
| 39 | "Create a filename for NAME in /tmp." | ||
| 40 | (expand-file-name name semantic-utest-temp-directory)) | ||
| 41 | |||
| 42 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
| 43 | ;; Data for C tests | ||
| 44 | |||
| 45 | (defvar semantic-utest-C-buffer-contents | ||
| 46 | "/* Test file for C language for Unit Tests */ | ||
| 47 | |||
| 48 | #include <stdio.h> | ||
| 49 | #include \"sutest.h\" | ||
| 50 | |||
| 51 | struct mystruct1 { | ||
| 52 | int slot11; | ||
| 53 | char slot12; | ||
| 54 | float slot13; | ||
| 55 | }; | ||
| 56 | |||
| 57 | int var1; | ||
| 58 | |||
| 59 | float funp1(char arg11, char arg12); | ||
| 60 | |||
| 61 | char fun2(int arg_21, int arg_22) /*1*/ | ||
| 62 | { | ||
| 63 | struct mystruct1 *ms1 = malloc(sizeof(struct mystruct1)); | ||
| 64 | |||
| 65 | char sv = calc_sv(var1); | ||
| 66 | |||
| 67 | if (var1 == 0) { | ||
| 68 | sv = 1; | ||
| 69 | } else if (arg_21 == 0) { | ||
| 70 | sv = 2; | ||
| 71 | } else if (arg_22 == 0) { | ||
| 72 | sv = 3; | ||
| 73 | } else { | ||
| 74 | sv = 4; | ||
| 75 | } | ||
| 76 | |||
| 77 | printf(\"SV = %d\\n\", sv); | ||
| 78 | |||
| 79 | /* Memory Leak */ | ||
| 80 | ms1.slot1 = sv; | ||
| 81 | |||
| 82 | return 'A' + sv; | ||
| 83 | } | ||
| 84 | " | ||
| 85 | "Contents of a C buffer initialized by this unit test. | ||
| 86 | Be sure to change `semantic-utest-C-name-contents' when you | ||
| 87 | change this variable.") | ||
| 88 | |||
| 89 | (defvar semantic-utest-C-h-buffer-contents | ||
| 90 | "/* Test file for C language header file for Unit Tests */ | ||
| 91 | |||
| 92 | int calc_sv(int); | ||
| 93 | |||
| 94 | " | ||
| 95 | "Contents of a C header file buffer initialized by this unit test.") | ||
| 96 | |||
| 97 | (defvar semantic-utest-C-filename (semantic-utest-fname "sutest.c") | ||
| 98 | "File to open and erase during this test for C.") | ||
| 99 | |||
| 100 | (defvar semantic-utest-C-filename-h | ||
| 101 | (concat (file-name-sans-extension semantic-utest-C-filename) | ||
| 102 | ".h") | ||
| 103 | "Header file filename for C") | ||
| 104 | |||
| 105 | |||
| 106 | (defvar semantic-utest-C-name-contents | ||
| 107 | '(("stdio.h" include | ||
| 108 | (:system-flag t) | ||
| 109 | nil (overlay 48 66 "sutest.c")) | ||
| 110 | ("sutest.h" include nil nil (overlay 67 86 "sutest.c")) | ||
| 111 | ("mystruct1" type | ||
| 112 | (:members | ||
| 113 | (("slot11" variable | ||
| 114 | (:type "int") | ||
| 115 | (reparse-symbol classsubparts) | ||
| 116 | (overlay 109 120 "sutest.c")) | ||
| 117 | ("slot12" variable | ||
| 118 | (:type "char") | ||
| 119 | (reparse-symbol classsubparts) | ||
| 120 | (overlay 123 135 "sutest.c")) | ||
| 121 | ("slot13" variable | ||
| 122 | (:type "float") | ||
| 123 | (reparse-symbol classsubparts) | ||
| 124 | (overlay 138 151 "sutest.c"))) | ||
| 125 | :type "struct") | ||
| 126 | nil (overlay 88 154 "sutest.c")) | ||
| 127 | ("var1" variable | ||
| 128 | (:type "int") | ||
| 129 | nil (overlay 156 165 "sutest.c")) | ||
| 130 | ("funp1" function | ||
| 131 | (:prototype-flag t :arguments | ||
| 132 | (("arg11" variable | ||
| 133 | (:type "char") | ||
| 134 | (reparse-symbol arg-sub-list) | ||
| 135 | (overlay 179 190 "sutest.c")) | ||
| 136 | ("arg12" variable | ||
| 137 | (:type "char") | ||
| 138 | (reparse-symbol arg-sub-list) | ||
| 139 | (overlay 191 202 "sutest.c"))) | ||
| 140 | :type "float") | ||
| 141 | nil (overlay 167 203 "sutest.c")) | ||
| 142 | ("fun2" function | ||
| 143 | (:arguments | ||
| 144 | (("arg_21" variable | ||
| 145 | (:type "int") | ||
| 146 | (reparse-symbol arg-sub-list) | ||
| 147 | (overlay 215 226 "sutest.c")) | ||
| 148 | ("arg_22" variable | ||
| 149 | (:type "int") | ||
| 150 | (reparse-symbol arg-sub-list) | ||
| 151 | (overlay 227 238 "sutest.c"))) | ||
| 152 | :type "char") | ||
| 153 | nil (overlay 205 566 "sutest.c"))) | ||
| 154 | "List of expected tag names for C.") | ||
| 155 | |||
| 156 | |||
| 157 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
| 158 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
| 159 | ;; Data for Python tests | ||
| 160 | |||
| 161 | (defvar semantic-utest-Python-buffer-contents | ||
| 162 | " | ||
| 163 | def fun1(a,b,c): | ||
| 164 | return a | ||
| 165 | |||
| 166 | def fun2(a,b,c): #1 | ||
| 167 | return b | ||
| 168 | |||
| 169 | " | ||
| 170 | |||
| 171 | |||
| 172 | ) | ||
| 173 | ; "pyhon test case. notice that python is indentation sensitive | ||
| 174 | |||
| 175 | |||
| 176 | (defvar semantic-utest-Python-name-contents | ||
| 177 | '(("fun1" function | ||
| 178 | (:arguments | ||
| 179 | (("a" variable nil | ||
| 180 | (reparse-symbol function_parameters) | ||
| 181 | (overlay 10 11 "tst.py")) | ||
| 182 | ("b" variable nil | ||
| 183 | (reparse-symbol function_parameters) | ||
| 184 | (overlay 12 13 "tst.py")) | ||
| 185 | ("c" variable nil | ||
| 186 | (reparse-symbol function_parameters) | ||
| 187 | (overlay 14 15 "tst.py")))) | ||
| 188 | nil (overlay 1 31 "tst.py")) | ||
| 189 | ("fun2" function | ||
| 190 | (:arguments | ||
| 191 | (("a" variable nil | ||
| 192 | (reparse-symbol function_parameters) | ||
| 193 | (overlay 41 42 "tst.py")) | ||
| 194 | ("b" variable nil | ||
| 195 | (reparse-symbol function_parameters) | ||
| 196 | (overlay 43 44 "tst.py")) | ||
| 197 | ("c" variable nil | ||
| 198 | (reparse-symbol function_parameters) | ||
| 199 | (overlay 45 46 "tst.py")))) | ||
| 200 | nil (overlay 32 65 "tst.py"))) | ||
| 201 | |||
| 202 | "List of expected tag names for Python.") | ||
| 203 | |||
| 204 | |||
| 205 | |||
| 206 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
| 207 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
| 208 | ;; Data for Java tests | ||
| 209 | |||
| 210 | (defvar semantic-utest-Java-buffer-contents | ||
| 211 | " | ||
| 212 | class JavaTest{ | ||
| 213 | void fun1(int a,int b){ | ||
| 214 | return a; | ||
| 215 | } | ||
| 216 | |||
| 217 | void fun2(int a,int b){ //1 | ||
| 218 | return b; | ||
| 219 | } | ||
| 220 | |||
| 221 | } | ||
| 222 | " | ||
| 223 | ) | ||
| 224 | |||
| 225 | (defvar semantic-utest-Java-name-contents | ||
| 226 | '(("JavaTest" type | ||
| 227 | (:members | ||
| 228 | (("fun1" function | ||
| 229 | (:arguments | ||
| 230 | (("a" variable | ||
| 231 | (:type "int") | ||
| 232 | (reparse-symbol formal_parameters) | ||
| 233 | (overlay 30 35 "JavaTest.java")) | ||
| 234 | ("b" variable | ||
| 235 | (:type "int") | ||
| 236 | (reparse-symbol formal_parameters) | ||
| 237 | (overlay 36 41 "JavaTest.java"))) | ||
| 238 | :type "void") | ||
| 239 | (reparse-symbol class_member_declaration) | ||
| 240 | (overlay 20 61 "JavaTest.java")) | ||
| 241 | ("fun2" function | ||
| 242 | (:arguments | ||
| 243 | (("a" variable | ||
| 244 | (:type "int") | ||
| 245 | (reparse-symbol formal_parameters) | ||
| 246 | (overlay 75 80 "JavaTest.java")) | ||
| 247 | ("b" variable | ||
| 248 | (:type "int") | ||
| 249 | (reparse-symbol formal_parameters) | ||
| 250 | (overlay 81 86 "JavaTest.java"))) | ||
| 251 | :type "void") | ||
| 252 | (reparse-symbol class_member_declaration) | ||
| 253 | (overlay 65 110 "JavaTest.java"))) | ||
| 254 | :type "class") | ||
| 255 | nil (overlay 2 113 "JavaTest.java"))) | ||
| 256 | "List of expected tag names for Java." | ||
| 257 | ) | ||
| 258 | |||
| 259 | |||
| 260 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
| 261 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
| 262 | ;; Data for Javascript tests | ||
| 263 | |||
| 264 | (defvar semantic-utest-Javascript-buffer-contents | ||
| 265 | " | ||
| 266 | function fun1(a, b){ | ||
| 267 | return a; | ||
| 268 | } | ||
| 269 | |||
| 270 | function fun2(a,b){ //1 | ||
| 271 | return b; | ||
| 272 | } | ||
| 273 | " | ||
| 274 | ) | ||
| 275 | |||
| 276 | |||
| 277 | (defvar semantic-utest-Javascript-name-contents | ||
| 278 | '(("fun1" function | ||
| 279 | (:arguments | ||
| 280 | (("a" variable nil | ||
| 281 | (reparse-symbol FormalParameterList) | ||
| 282 | (overlay 15 16 "tst.js")) | ||
| 283 | ("b" variable nil | ||
| 284 | (reparse-symbol FormalParameterList) | ||
| 285 | (overlay 18 19 "tst.js")))) | ||
| 286 | nil (overlay 1 39 "tst.js")) | ||
| 287 | ("fun2" function | ||
| 288 | (:arguments | ||
| 289 | (("a" variable nil | ||
| 290 | (reparse-symbol FormalParameterList) | ||
| 291 | (overlay 55 56 "tst.js")) | ||
| 292 | ("b" variable nil | ||
| 293 | (reparse-symbol FormalParameterList) | ||
| 294 | (overlay 57 58 "tst.js")))) | ||
| 295 | nil (overlay 41 82 "tst.js"))) | ||
| 296 | |||
| 297 | "List of expected tag names for Javascript.") | ||
| 298 | |||
| 299 | |||
| 300 | |||
| 301 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
| 302 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
| 303 | ;; Data for Makefile tests | ||
| 304 | |||
| 305 | (defvar semantic-utest-Makefile-buffer-contents | ||
| 306 | " | ||
| 307 | t1: | ||
| 308 | \techo t1 | ||
| 309 | |||
| 310 | t2:t1 #1 | ||
| 311 | \techo t2 | ||
| 312 | |||
| 313 | |||
| 314 | " | ||
| 315 | ) | ||
| 316 | |||
| 317 | |||
| 318 | (defvar semantic-utest-Makefile-name-contents | ||
| 319 | '(("t1" function nil nil (overlay 1 9 "Makefile")) | ||
| 320 | ("t2" function | ||
| 321 | (:arguments | ||
| 322 | ("t1")) | ||
| 323 | nil (overlay 18 28 "Makefile"))) | ||
| 324 | "List of expected tag names for Makefile.") | ||
| 325 | |||
| 326 | |||
| 327 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
| 328 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
| 329 | ;; Data for Scheme tests | ||
| 330 | |||
| 331 | (defvar semantic-utest-Scheme-buffer-contents | ||
| 332 | " | ||
| 333 | (define fun1 2) | ||
| 334 | |||
| 335 | (define fun2 3 ;1 | ||
| 336 | ) | ||
| 337 | ") | ||
| 338 | |||
| 339 | (defvar semantic-utest-Scheme-name-contents | ||
| 340 | '(("fun1" variable | ||
| 341 | (:default-value ("2")) | ||
| 342 | nil (overlay 3 18 "tst.scm")) | ||
| 343 | ("fun2" variable | ||
| 344 | (:default-value ("3")) | ||
| 345 | nil (overlay 21 55 "tst.scm"))) | ||
| 346 | ) | ||
| 347 | |||
| 348 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
| 349 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
| 350 | ;; Data for Html tests | ||
| 351 | |||
| 352 | (defvar semantic-utest-Html-buffer-contents | ||
| 353 | " | ||
| 354 | <html> | ||
| 355 | <body> | ||
| 356 | <h1>hello</h1> | ||
| 357 | </body><!--1--> | ||
| 358 | </html> | ||
| 359 | " | ||
| 360 | ) | ||
| 361 | |||
| 362 | (defvar semantic-utest-Html-name-contents | ||
| 363 | '(("hello" section | ||
| 364 | (:members | ||
| 365 | (("hello" section nil nil (overlay 21 24 "tst.html")))) | ||
| 366 | nil (overlay 10 15 "tst.html"))) | ||
| 367 | ) | ||
| 368 | |||
| 369 | |||
| 370 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
| 371 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
| 372 | ;; Data for PHP tests | ||
| 373 | |||
| 374 | (defvar semantic-utest-PHP-buffer-contents | ||
| 375 | "<?php | ||
| 376 | |||
| 377 | function fun1(){ | ||
| 378 | return \"fun1\"; | ||
| 379 | } | ||
| 380 | |||
| 381 | function fun2($arg1){ | ||
| 382 | $output = \"argument to fun2: \" . $arg1; | ||
| 383 | return $output; | ||
| 384 | } | ||
| 385 | |||
| 386 | class aClass { | ||
| 387 | public function fun1($a, $b){ | ||
| 388 | return $a; | ||
| 389 | } | ||
| 390 | |||
| 391 | public function fun2($a, $b){ | ||
| 392 | return $b; | ||
| 393 | } | ||
| 394 | } | ||
| 395 | ?> " | ||
| 396 | ) | ||
| 397 | |||
| 398 | (defvar semantic-utest-PHP-name-contents | ||
| 399 | '(("fun1" function nil | ||
| 400 | nil (overlay 9 45 "phptest.php")) | ||
| 401 | ("fun2" function | ||
| 402 | (:arguments (("$arg1" variable nil (reparse-symbol formal_parameters) (overlay 61 66 "phptest.php")))) | ||
| 403 | nil | ||
| 404 | (overlay 47 132 "phptest.php")) | ||
| 405 | ("aClass" type | ||
| 406 | (:members (("fun1" function | ||
| 407 | (:typemodifiers ("public") :arguments | ||
| 408 | (("$a" variable nil (reparse-symbol formal_parameters) (overlay 174 176 "phptest.php")) | ||
| 409 | ("$b" variable nil (reparse-symbol formal_parameters) (overlay 178 180 "phptest.php")))) | ||
| 410 | |||
| 411 | nil | ||
| 412 | (overlay 153 204 "phptest.php")) | ||
| 413 | |||
| 414 | ("fun2" function | ||
| 415 | (:typemodifiers ("public") :arguments | ||
| 416 | (("$a" variable nil (reparse-symbol formal_parameters) (overlay 230 232 "phptest.php")) | ||
| 417 | ("$b" variable nil (reparse-symbol formal_parameters) (overlay 234 236 "phptest.php")) | ||
| 418 | )) | ||
| 419 | nil | ||
| 420 | (overlay 209 260 "phptest.php"))) :type "class") | ||
| 421 | nil | ||
| 422 | (overlay 135 262 "phptest.php")) | ||
| 423 | ) | ||
| 424 | "Expected results from the PHP Unit test" | ||
| 425 | ) | ||
| 426 | |||
| 427 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
| 428 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
| 429 | ;; Data for Csharp C# tests | ||
| 430 | |||
| 431 | (defvar semantic-utest-Csharp-buffer-contents | ||
| 432 | " | ||
| 433 | class someClass { | ||
| 434 | int fun1(int a, int b) { | ||
| 435 | return a; } | ||
| 436 | int fun2(int a, int b) { | ||
| 437 | return b; } | ||
| 438 | } | ||
| 439 | ") | ||
| 440 | |||
| 441 | (defvar semantic-utest-Csharp-name-contents | ||
| 442 | '(("someClass" type | ||
| 443 | (:members | ||
| 444 | (("fun1" function | ||
| 445 | (:arguments | ||
| 446 | (("a" variable | ||
| 447 | (:type "int") | ||
| 448 | (reparse-symbol formal_parameters) | ||
| 449 | (overlay 30 35 "tst.cs")) | ||
| 450 | ("b" variable | ||
| 451 | (:type "int") | ||
| 452 | (reparse-symbol formal_parameters) | ||
| 453 | (overlay 37 42 "tst.cs"))) | ||
| 454 | :type "int") | ||
| 455 | (reparse-symbol class_member_declaration) | ||
| 456 | (overlay 21 61 "tst.cs")) | ||
| 457 | ("fun2" function | ||
| 458 | (:arguments | ||
| 459 | (("a" variable | ||
| 460 | (:type "int") | ||
| 461 | (reparse-symbol formal_parameters) | ||
| 462 | (overlay 73 78 "tst.cs")) | ||
| 463 | ("b" variable | ||
| 464 | (:type "int") | ||
| 465 | (reparse-symbol formal_parameters) | ||
| 466 | (overlay 80 85 "tst.cs"))) | ||
| 467 | :type "int") | ||
| 468 | (reparse-symbol class_member_declaration) | ||
| 469 | (overlay 64 104 "tst.cs"))) | ||
| 470 | :type "class") | ||
| 471 | nil (overlay 1 106 "tst.cs"))) | ||
| 472 | ) | ||
| 473 | |||
| 474 | |||
| 475 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
| 476 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
| 477 | |||
| 478 | |||
| 479 | |||
| 480 | (defun semantic-utest-makebuffer (filename contents) | ||
| 481 | "Create a buffer for FILENAME for use in a unit test. | ||
| 482 | Pre-fill the buffer with CONTENTS." | ||
| 483 | (let ((buff (semantic-find-file-noselect filename))) | ||
| 484 | (set-buffer buff) | ||
| 485 | (setq buffer-offer-save nil) | ||
| 486 | (font-lock-mode -1) ;; Font lock has issues in Emacs 23 | ||
| 487 | (toggle-read-only -1) ;; In case /tmp doesn't exist. | ||
| 488 | (erase-buffer) | ||
| 489 | (insert contents) | ||
| 490 | ;(semantic-fetch-tags) ;JAVE could this go here? | ||
| 491 | (set-buffer-modified-p nil) | ||
| 492 | buff | ||
| 493 | ) | ||
| 494 | ) | ||
| 495 | |||
| 496 | (defun semantic-utest-C () | ||
| 497 | "Run semantic's C unit test." | ||
| 498 | (interactive) | ||
| 499 | (save-excursion | ||
| 500 | (let ((buff (semantic-utest-makebuffer semantic-utest-C-filename semantic-utest-C-buffer-contents)) | ||
| 501 | (buff2 (semantic-utest-makebuffer semantic-utest-C-filename-h semantic-utest-C-h-buffer-contents)) | ||
| 502 | ) | ||
| 503 | (semantic-fetch-tags) | ||
| 504 | (set-buffer buff) | ||
| 505 | |||
| 506 | ;; Turn off a range of modes | ||
| 507 | (semantic-idle-scheduler-mode -1) | ||
| 508 | |||
| 509 | ;; Turn on some modes | ||
| 510 | (semantic-highlight-edits-mode 1) | ||
| 511 | |||
| 512 | ;; Update tags, and show it. | ||
| 513 | (semantic-fetch-tags) | ||
| 514 | |||
| 515 | (switch-to-buffer buff) | ||
| 516 | (sit-for 0) | ||
| 517 | |||
| 518 | ;; Run the tests. | ||
| 519 | ;;(message "First parsing test.") | ||
| 520 | (semantic-utest-verify-names semantic-utest-C-name-contents) | ||
| 521 | |||
| 522 | ;;(message "Invalid tag test.") | ||
| 523 | (semantic-utest-last-invalid semantic-utest-C-name-contents '("fun2") "/\\*1\\*/" "/* Deleted this line */") | ||
| 524 | (semantic-utest-verify-names semantic-utest-C-name-contents) | ||
| 525 | |||
| 526 | (set-buffer-modified-p nil) | ||
| 527 | ;; Clean up | ||
| 528 | ;; (kill-buffer buff) | ||
| 529 | ;; (kill-buffer buff2) | ||
| 530 | )) | ||
| 531 | (message "All C tests passed.") | ||
| 532 | ) | ||
| 533 | |||
| 534 | |||
| 535 | |||
| 536 | |||
| 537 | (defun semantic-utest-generic (testname filename contents name-contents names-removed killme insertme) | ||
| 538 | "Generic unit test according to template. | ||
| 539 | Should work for languages withouth .h files, python javascript java. | ||
| 540 | TESTNAME is the name of the test. | ||
| 541 | FILENAME is the name of the file to create. | ||
| 542 | CONTENTS is the contents of the file to test. | ||
| 543 | NAME-CONTENTS is the list of names that should be in the contents. | ||
| 544 | NAMES-REMOVED is the list of names that gets removed in the removal step. | ||
| 545 | KILLME is the name of items to be killed. | ||
| 546 | INSERTME is the text to be inserted after the deletion." | ||
| 547 | (save-excursion | ||
| 548 | (let ((buff (semantic-utest-makebuffer filename contents)) | ||
| 549 | ) | ||
| 550 | ;; Turn off a range of modes | ||
| 551 | (semantic-idle-scheduler-mode -1) | ||
| 552 | |||
| 553 | ;; Turn on some modes | ||
| 554 | (semantic-highlight-edits-mode 1) | ||
| 555 | |||
| 556 | ;; Update tags, and show it. | ||
| 557 | (semantic-fetch-tags) | ||
| 558 | (switch-to-buffer buff) | ||
| 559 | (sit-for 0) | ||
| 560 | |||
| 561 | ;; Run the tests. | ||
| 562 | ;;(message "First parsing test %s." testname) | ||
| 563 | (semantic-utest-verify-names name-contents) | ||
| 564 | |||
| 565 | ;;(message "Invalid tag test %s." testname) | ||
| 566 | (semantic-utest-last-invalid name-contents names-removed killme insertme) | ||
| 567 | (semantic-utest-verify-names name-contents) | ||
| 568 | |||
| 569 | (set-buffer-modified-p nil) | ||
| 570 | ;; Clean up | ||
| 571 | ;; (kill-buffer buff) | ||
| 572 | )) | ||
| 573 | (message "All %s tests passed." testname) | ||
| 574 | ) | ||
| 575 | |||
| 576 | (defun semantic-utest-Python() | ||
| 577 | (interactive) | ||
| 578 | (if (fboundp 'python-mode) | ||
| 579 | (semantic-utest-generic "Python" (semantic-utest-fname "pytest.py") semantic-utest-Python-buffer-contents semantic-utest-Python-name-contents '("fun2") "#1" "#deleted line") | ||
| 580 | (message "Skilling Python test: NO major mode.")) | ||
| 581 | ) | ||
| 582 | |||
| 583 | |||
| 584 | (defun semantic-utest-Javascript() | ||
| 585 | (interactive) | ||
| 586 | (if (fboundp 'javascript-mode) | ||
| 587 | (semantic-utest-generic "Javascript" (semantic-utest-fname "javascripttest.js") semantic-utest-Javascript-buffer-contents semantic-utest-Javascript-name-contents '("fun2") "//1" "//deleted line") | ||
| 588 | (message "Skipping JavaScript test: NO major mode.")) | ||
| 589 | ) | ||
| 590 | |||
| 591 | (defun semantic-utest-Java() | ||
| 592 | (interactive) | ||
| 593 | ;; If JDE is installed, it might mess things up depending on the version | ||
| 594 | ;; that was installed. | ||
| 595 | (let ((auto-mode-alist '(("\\.java\\'" . java-mode)))) | ||
| 596 | (semantic-utest-generic "Java" (semantic-utest-fname "JavaTest.java") semantic-utest-Java-buffer-contents semantic-utest-Java-name-contents '("fun2") "//1" "//deleted line") | ||
| 597 | )) | ||
| 598 | |||
| 599 | (defun semantic-utest-Makefile() | ||
| 600 | (interactive) | ||
| 601 | (semantic-utest-generic "Makefile" (semantic-utest-fname "Makefile") semantic-utest-Makefile-buffer-contents semantic-utest-Makefile-name-contents '("fun2") "#1" "#deleted line") | ||
| 602 | ) | ||
| 603 | |||
| 604 | (defun semantic-utest-Scheme() | ||
| 605 | (interactive) | ||
| 606 | (semantic-utest-generic "Scheme" (semantic-utest-fname "tst.scm") semantic-utest-Scheme-buffer-contents semantic-utest-Scheme-name-contents '("fun2") ";1" ";deleted line") | ||
| 607 | ) | ||
| 608 | |||
| 609 | |||
| 610 | (defun semantic-utest-Html() | ||
| 611 | (interactive) | ||
| 612 | ;; Disable html-helper auto-fill-in mode. | ||
| 613 | (let ((html-helper-build-new-buffer nil)) | ||
| 614 | (semantic-utest-generic "HTML" (semantic-utest-fname "tst.html") semantic-utest-Html-buffer-contents semantic-utest-Html-name-contents '("fun2") "<!--1-->" "<!--deleted line-->") | ||
| 615 | )) | ||
| 616 | |||
| 617 | (defun semantic-utest-PHP() | ||
| 618 | (interactive) | ||
| 619 | (if (fboundp 'php-mode) | ||
| 620 | (semantic-utest-generic "PHP" (semantic-utest-fname "phptest.php") semantic-utest-PHP-buffer-contents semantic-utest-PHP-name-contents '("fun1") "fun2" "%^@") | ||
| 621 | (message "Skipping PHP Test. No php-mode loaded.")) | ||
| 622 | ) | ||
| 623 | |||
| 624 | ;look at http://mfgames.com/linux/csharp-mode | ||
| 625 | (defun semantic-utest-Csharp() ;; hmm i dont even know how to edit a scharp file. need a csharp mode implementation i suppose | ||
| 626 | (interactive) | ||
| 627 | (if (fboundp 'csharp-mode) | ||
| 628 | (semantic-utest-generic "C#" (semantic-utest-fname "csharptest.cs") semantic-utest-Csharp-buffer-contents semantic-utest-Csharp-name-contents '("fun2") "//1" "//deleted line") | ||
| 629 | (message "Skipping C# test. No csharp-mode loaded.")) | ||
| 630 | ) | ||
| 631 | |||
| 632 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
| 633 | ;; stubs | ||
| 634 | |||
| 635 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
| 636 | ; stuff for Erlang | ||
| 637 | ;;-module(hello). | ||
| 638 | ;-export([hello_world/0]). | ||
| 639 | ; | ||
| 640 | ;hello_world()-> | ||
| 641 | ; io:format("Hello World ~n"). | ||
| 642 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
| 643 | ;(defun semantic-utest-Erlang() | ||
| 644 | ; (interactive) | ||
| 645 | ; (semantic-utest-generic "Erlang" (semantic-utest-fname "tst.erl") semantic-utest-Erlang-buffer-contents semantic-utest-Erlang-name-contents '("fun2") "//1" "//deleted line") | ||
| 646 | ; ) | ||
| 647 | ; | ||
| 648 | ;;texi is also supported | ||
| 649 | ;(defun semantic-utest-Texi() | ||
| 650 | ; (interactive) | ||
| 651 | ; (semantic-utest-generic "texi" (semantic-utest-fname "tst.texi") semantic-utest-Texi-buffer-contents semantic-utest-Texi-name-contents '("fun2") "//1" "//deleted line") | ||
| 652 | ; ) | ||
| 653 | |||
| 654 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
| 655 | |||
| 656 | ;;;###autoload | ||
| 657 | (defun semantic-utest-main() | ||
| 658 | (interactive) | ||
| 659 | "call all utests" | ||
| 660 | (cedet-utest-log-start "multi-lang parsing") | ||
| 661 | (cedet-utest-log " * C tests...") | ||
| 662 | (semantic-utest-C) | ||
| 663 | (cedet-utest-log " * Python tests...") | ||
| 664 | (semantic-utest-Python) | ||
| 665 | (cedet-utest-log " * Java tests...") | ||
| 666 | (semantic-utest-Java) | ||
| 667 | (cedet-utest-log " * Javascript tests...") | ||
| 668 | (semantic-utest-Javascript) | ||
| 669 | (cedet-utest-log " * Makefile tests...") | ||
| 670 | (semantic-utest-Makefile) | ||
| 671 | (cedet-utest-log " * Scheme tests...") | ||
| 672 | (semantic-utest-Scheme) | ||
| 673 | (cedet-utest-log " * Html tests...") | ||
| 674 | (semantic-utest-Html) | ||
| 675 | (cedet-utest-log " * PHP tests...") | ||
| 676 | (semantic-utest-PHP) | ||
| 677 | (cedet-utest-log " * Csharp tests...") | ||
| 678 | (semantic-utest-Csharp) | ||
| 679 | |||
| 680 | (cedet-utest-log-shutdown "multi-lang parsing") | ||
| 681 | ) | ||
| 682 | |||
| 683 | ;;; Buffer contents validation | ||
| 684 | ;; | ||
| 685 | (defun semantic-utest-match-attributes (attr1 attr2 skipnames) | ||
| 686 | "Compare attribute lists ATTR1 and ATTR2. | ||
| 687 | Argument SKIPNAMES is a list of names that may be child nodes to skip." | ||
| 688 | (let ((res t)) | ||
| 689 | (while (and res attr1 attr2) | ||
| 690 | |||
| 691 | ;; Compare | ||
| 692 | (setq res | ||
| 693 | (cond ((and (listp (car attr1)) | ||
| 694 | (semantic-tag-p (car (car attr1)))) | ||
| 695 | ;; Compare the list of tags... | ||
| 696 | (semantic-utest-taglists-equivalent-p | ||
| 697 | (car attr2) (car attr1) skipnames) | ||
| 698 | ) | ||
| 699 | (t | ||
| 700 | (equal (car attr1) (car attr2))))) | ||
| 701 | |||
| 702 | (if (not res) | ||
| 703 | (error "TAG INTERNAL DIFF: %S %S" | ||
| 704 | (car attr1) (car attr2))) | ||
| 705 | |||
| 706 | (setq attr1 (cdr attr1) | ||
| 707 | attr2 (cdr attr2))) | ||
| 708 | res)) | ||
| 709 | |||
| 710 | (defun semantic-utest-equivalent-tag-p (tag1 tag2 skipnames) | ||
| 711 | "Determine if TAG1 and TAG2 are the same. | ||
| 712 | SKIPNAMES includes lists of possible child nodes that should be missing." | ||
| 713 | (and (equal (semantic-tag-name tag1) (semantic-tag-name tag2)) | ||
| 714 | (semantic-tag-of-class-p tag1 (semantic-tag-class tag2)) | ||
| 715 | (semantic-utest-match-attributes | ||
| 716 | (semantic-tag-attributes tag1) (semantic-tag-attributes tag2) | ||
| 717 | skipnames) | ||
| 718 | )) | ||
| 719 | |||
| 720 | (defun semantic-utest-taglists-equivalent-p (table names skipnames) | ||
| 721 | "Compare TABLE and NAMES, where skipnames allow list1 to be different. | ||
| 722 | SKIPNAMES is a list of names that should be skipped in the NAMES list." | ||
| 723 | (let ((SN skipnames)) | ||
| 724 | (while SN | ||
| 725 | (setq names (remove (car SN) names)) | ||
| 726 | (setq SN (cdr SN)))) | ||
| 727 | (while (and names table) | ||
| 728 | (if (not (semantic-utest-equivalent-tag-p (car names) | ||
| 729 | (car table) | ||
| 730 | skipnames)) | ||
| 731 | (error "Expected %s, found %s" | ||
| 732 | (semantic-format-tag-prototype (car names)) | ||
| 733 | (semantic-format-tag-prototype (car table)))) | ||
| 734 | (setq names (cdr names) | ||
| 735 | table (cdr table))) | ||
| 736 | (when names (error "Items forgotten: %S" | ||
| 737 | (mapcar 'semantic-tag-name names) | ||
| 738 | )) | ||
| 739 | (when table (error "Items extra: %S" | ||
| 740 | (mapcar 'semantic-tag-name table))) | ||
| 741 | t) | ||
| 742 | |||
| 743 | (defun semantic-utest-verify-names (name-contents &optional skipnames) | ||
| 744 | "Verify the names of the test buffer from NAME-CONTENTS. | ||
| 745 | Argument SKIPNAMES is a list of names that should be skipped | ||
| 746 | when analyzing the file. | ||
| 747 | |||
| 748 | JAVE this thing would need to be recursive to handle java and csharp" | ||
| 749 | (let ((names name-contents) | ||
| 750 | (table (semantic-fetch-tags)) | ||
| 751 | ) | ||
| 752 | (semantic-utest-taglists-equivalent-p table names skipnames) | ||
| 753 | )) | ||
| 754 | |||
| 755 | ;;;;;;;;;;;;;;;;;;;;;;;; | ||
| 756 | ; JAVE redefine a new validation function | ||
| 757 | ; is not quite as good as the old one yet | ||
| 758 | (defun semantic-utest-verify-names-jave (name-contents &optional skipnames) | ||
| 759 | "JAVE version of `semantic-utest-verify-names'. | ||
| 760 | NAME-CONTENTS is a sample of the tags buffer to test against. | ||
| 761 | SKIPNAMES is a list of names to remove from NAME-CONTENTS" | ||
| 762 | (assert (semantic-utest-verify-names-2 name-contents (semantic-fetch-tags)) | ||
| 763 | nil "failed test") | ||
| 764 | ) | ||
| 765 | |||
| 766 | (defun semantic-utest-verify-names-2 (l1 l2) | ||
| 767 | (cond ( (and (consp l1) (equal (car l1) 'overlay)) | ||
| 768 | (overlayp l2)) | ||
| 769 | ((not (consp l1)) | ||
| 770 | (equal l1 l2)) | ||
| 771 | ((consp l1) | ||
| 772 | (and (semantic-utest-verify-names-2 (car l1) (car l2)) (semantic-utest-verify-names-2 (cdr l1) (cdr l2)))) | ||
| 773 | (t (error "internal error")))) | ||
| 774 | |||
| 775 | |||
| 776 | |||
| 777 | |||
| 778 | |||
| 779 | ;;; Kill indicator line | ||
| 780 | ;; | ||
| 781 | (defvar semantic-utest-last-kill-text nil | ||
| 782 | "The text from the last kill.") | ||
| 783 | |||
| 784 | (defvar semantic-utest-last-kill-pos nil | ||
| 785 | "The position of the last kill.") | ||
| 786 | |||
| 787 | (defun semantic-utest-kill-indicator ( killme insertme) | ||
| 788 | "Kill the line with KILLME on it and insert INSERTME in its place." | ||
| 789 | (goto-char (point-min)) | ||
| 790 | ; (re-search-forward (concat "/\\*" indicator "\\*/")); JAVE this isnt generic enough for different lagnuages | ||
| 791 | (re-search-forward killme) | ||
| 792 | (beginning-of-line) | ||
| 793 | (setq semantic-utest-last-kill-pos (point)) | ||
| 794 | (setq semantic-utest-last-kill-text | ||
| 795 | (buffer-substring (point) (point-at-eol))) | ||
| 796 | (delete-region (point) (point-at-eol)) | ||
| 797 | (insert insertme) | ||
| 798 | (sit-for 0) | ||
| 799 | ) | ||
| 800 | |||
| 801 | (defun semantic-utest-unkill-indicator () | ||
| 802 | "Unkill the last indicator." | ||
| 803 | (goto-char semantic-utest-last-kill-pos) | ||
| 804 | (delete-region (point) (point-at-eol)) | ||
| 805 | (insert semantic-utest-last-kill-text) | ||
| 806 | (sit-for 0) | ||
| 807 | ) | ||
| 808 | |||
| 809 | ;;; EDITING TESTS | ||
| 810 | ;; | ||
| 811 | |||
| 812 | (defun semantic-utest-last-invalid (name-contents names-removed killme insertme) | ||
| 813 | "Make the last fcn invalid." | ||
| 814 | (semantic-utest-kill-indicator killme insertme) | ||
| 815 | ; (semantic-utest-verify-names name-contents names-removed); verify its gone ;new validator doesnt handle skipnames yet | ||
| 816 | (semantic-utest-unkill-indicator);put back killed stuff | ||
| 817 | ) | ||
| 818 | |||
| 819 | |||
| 820 | |||
| 821 | |||
| 822 | ;"#<overlay from \\([0-9]+\\) to \\([0-9]+\\) in \\([^>]*\\)>" | ||
| 823 | ;#<overlay from \([0-9]+\) to \([0-9]+\) in \([^>]*\)> | ||
| 824 | ;(overlay \1 \2 "\3") | ||
| 825 | |||
| 826 | |||
| 827 | ;; JAVE | ||
| 828 | ;; these are some unit tests for cedet that I got from Eric and modified a bit for: | ||
| 829 | ;; python | ||
| 830 | ;; javascript | ||
| 831 | ;; java | ||
| 832 | ;; I tried to generalize the structure of the tests a bit to make it easier to add languages | ||
| 833 | |||
| 834 | ;; Mail from Eric: | ||
| 835 | ;; Many items in the checklist look like: | ||
| 836 | |||
| 837 | ;; M-x global-semantic-highlight-edits-mode RET | ||
| 838 | ;; - Edit a file. See the highlight of newly inserted text. | ||
| 839 | ;; - Customize `semantic-edits-verbose-flag' to be non-nil. | ||
| 840 | ;; - Wait for the idle scheduler, it should clean up the edits. | ||
| 841 | ;; - observe messages from incremental parser. Do they relate | ||
| 842 | ;; to the edits? | ||
| 843 | ;; - M-x bovinate RET - verify your changes are reflected. | ||
| 844 | |||
| 845 | ;; It's all about watching the behavior. Timers go off, things get | ||
| 846 | ;; cleaned up, you type in new changes, etc. An example I tried to | ||
| 847 | ;; do is below, but covers only 1 language, and not very well at that. | ||
| 848 | ;; I seem to remember seeing a unit test framework going by one of the | ||
| 849 | ;; lists. I'm not sure if that would help. | ||
| 850 | |||
| 851 | ;; Another that might be automatable: | ||
| 852 | |||
| 853 | ;; M-x semantic-analyze-current-context RET | ||
| 854 | ;; - Do this in different contexts in your language | ||
| 855 | ;; files. Verify that reasonable results are returned | ||
| 856 | ;; such as identification of assignments, function arguments, etc. | ||
| 857 | |||
| 858 | ;; Anyway, those are some ideas. Any effort you put it will be helpful! | ||
| 859 | |||
| 860 | ;; Thanks | ||
| 861 | ;; Eric | ||
| 862 | |||
| 863 | ;; ----------- | ||
| 864 | |||
| 865 | |||
| 866 | |||
| 867 | ;;; semantic-utest.el ends here | ||
diff --git a/test/cedet/srecode-tests.el b/test/cedet/srecode-tests.el new file mode 100644 index 00000000000..0c13936829d --- /dev/null +++ b/test/cedet/srecode-tests.el | |||
| @@ -0,0 +1,266 @@ | |||
| 1 | ;;; From srecode-fields: | ||
| 2 | |||
| 3 | (require 'srecode/fields) | ||
| 4 | |||
| 5 | (defvar srecode-field-utest-text | ||
| 6 | "This is a test buffer. | ||
| 7 | |||
| 8 | It is filled with some text." | ||
| 9 | "Text for tests.") | ||
| 10 | |||
| 11 | (defun srecode-field-utest () | ||
| 12 | "Test the srecode field manager." | ||
| 13 | (interactive) | ||
| 14 | (if (featurep 'xemacs) | ||
| 15 | (message "There is no XEmacs support for SRecode Fields.") | ||
| 16 | (srecode-field-utest-impl))) | ||
| 17 | |||
| 18 | (defun srecode-field-utest-impl () | ||
| 19 | "Implementation of the SRecode field utest." | ||
| 20 | (save-excursion | ||
| 21 | (find-file "/tmp/srecode-field-test.txt") | ||
| 22 | |||
| 23 | (erase-buffer) | ||
| 24 | (goto-char (point-min)) | ||
| 25 | (insert srecode-field-utest-text) | ||
| 26 | (set-buffer-modified-p nil) | ||
| 27 | |||
| 28 | ;; Test basic field generation. | ||
| 29 | (let ((srecode-field-archive nil) | ||
| 30 | (f nil)) | ||
| 31 | |||
| 32 | (end-of-line) | ||
| 33 | (forward-word -1) | ||
| 34 | |||
| 35 | (setq f (srecode-field "Test" | ||
| 36 | :name "TEST" | ||
| 37 | :start 6 | ||
| 38 | :end 8)) | ||
| 39 | |||
| 40 | (when (or (not (slot-boundp f 'overlay)) (not (oref f overlay))) | ||
| 41 | (error "Field test: Overlay info not created for field")) | ||
| 42 | |||
| 43 | (when (and (overlay-p (oref f overlay)) | ||
| 44 | (not (overlay-get (oref f overlay) 'srecode-init-only))) | ||
| 45 | (error "Field creation overlay is not tagged w/ init flag")) | ||
| 46 | |||
| 47 | (srecode-overlaid-activate f) | ||
| 48 | |||
| 49 | (when (or (not (overlay-p (oref f overlay))) | ||
| 50 | (overlay-get (oref f overlay) 'srecode-init-only)) | ||
| 51 | (error "New field overlay not created during activation")) | ||
| 52 | |||
| 53 | (when (not (= (length srecode-field-archive) 1)) | ||
| 54 | (error "Field test: Incorrect number of elements in the field archive")) | ||
| 55 | (when (not (eq f (car srecode-field-archive))) | ||
| 56 | (error "Field test: Field did not auto-add itself to the field archive")) | ||
| 57 | |||
| 58 | (when (not (overlay-get (oref f overlay) 'keymap)) | ||
| 59 | (error "Field test: Overlay keymap not set")) | ||
| 60 | |||
| 61 | (when (not (string= "is" (srecode-overlaid-text f))) | ||
| 62 | (error "Field test: Expected field text 'is', not %s" | ||
| 63 | (srecode-overlaid-text f))) | ||
| 64 | |||
| 65 | ;; Test deletion. | ||
| 66 | (srecode-delete f) | ||
| 67 | |||
| 68 | (when (slot-boundp f 'overlay) | ||
| 69 | (error "Field test: Overlay not deleted after object delete")) | ||
| 70 | ) | ||
| 71 | |||
| 72 | ;; Test basic region construction. | ||
| 73 | (let* ((srecode-field-archive nil) | ||
| 74 | (reg nil) | ||
| 75 | (fields | ||
| 76 | (list | ||
| 77 | (srecode-field "Test1" :name "TEST-1" :start 5 :end 10) | ||
| 78 | (srecode-field "Test2" :name "TEST-2" :start 15 :end 20) | ||
| 79 | (srecode-field "Test3" :name "TEST-3" :start 25 :end 30) | ||
| 80 | |||
| 81 | (srecode-field "Test4" :name "TEST-4" :start 35 :end 35)) | ||
| 82 | )) | ||
| 83 | |||
| 84 | (when (not (= (length srecode-field-archive) 4)) | ||
| 85 | (error "Region Test: Found %d fields. Expected 4" | ||
| 86 | (length srecode-field-archive))) | ||
| 87 | |||
| 88 | (setq reg (srecode-template-inserted-region "REG" | ||
| 89 | :start 4 | ||
| 90 | :end 40)) | ||
| 91 | |||
| 92 | (srecode-overlaid-activate reg) | ||
| 93 | |||
| 94 | ;; Make sure it was cleared. | ||
| 95 | (when srecode-field-archive | ||
| 96 | (error "Region Test: Did not clear field archive")) | ||
| 97 | |||
| 98 | ;; Auto-positioning. | ||
| 99 | (when (not (eq (point) 5)) | ||
| 100 | (error "Region Test: Did not reposition on first field")) | ||
| 101 | |||
| 102 | ;; Active region | ||
| 103 | (when (not (eq (srecode-active-template-region) reg)) | ||
| 104 | (error "Region Test: Active region not set")) | ||
| 105 | |||
| 106 | ;; Various sizes | ||
| 107 | (mapc (lambda (T) | ||
| 108 | (if (string= (object-name-string T) "Test4") | ||
| 109 | (progn | ||
| 110 | (when (not (srecode-empty-region-p T)) | ||
| 111 | (error "Field %s is not empty" | ||
| 112 | (object-name T))) | ||
| 113 | ) | ||
| 114 | (when (not (= (srecode-region-size T) 5)) | ||
| 115 | (error "Calculated size of %s was not 5" | ||
| 116 | (object-name T))))) | ||
| 117 | fields) | ||
| 118 | |||
| 119 | ;; Make sure things stay up after a 'command'. | ||
| 120 | (srecode-field-post-command) | ||
| 121 | (when (not (eq (srecode-active-template-region) reg)) | ||
| 122 | (error "Region Test: Active region did not stay up")) | ||
| 123 | |||
| 124 | ;; Test field movement. | ||
| 125 | (when (not (eq (srecode-overlaid-at-point 'srecode-field) | ||
| 126 | (nth 0 fields))) | ||
| 127 | (error "Region Test: Field %s not under point" | ||
| 128 | (object-name (nth 0 fields)))) | ||
| 129 | |||
| 130 | (srecode-field-next) | ||
| 131 | |||
| 132 | (when (not (eq (srecode-overlaid-at-point 'srecode-field) | ||
| 133 | (nth 1 fields))) | ||
| 134 | (error "Region Test: Field %s not under point" | ||
| 135 | (object-name (nth 1 fields)))) | ||
| 136 | |||
| 137 | (srecode-field-prev) | ||
| 138 | |||
| 139 | (when (not (eq (srecode-overlaid-at-point 'srecode-field) | ||
| 140 | (nth 0 fields))) | ||
| 141 | (error "Region Test: Field %s not under point" | ||
| 142 | (object-name (nth 0 fields)))) | ||
| 143 | |||
| 144 | ;; Move cursor out of the region and have everything cleaned up. | ||
| 145 | (goto-char 42) | ||
| 146 | (srecode-field-post-command) | ||
| 147 | (when (srecode-active-template-region) | ||
| 148 | (error "Region Test: Active region did not clear on move out")) | ||
| 149 | |||
| 150 | (mapc (lambda (T) | ||
| 151 | (when (slot-boundp T 'overlay) | ||
| 152 | (error "Overlay did not clear off of of field %s" | ||
| 153 | (object-name T)))) | ||
| 154 | fields) | ||
| 155 | |||
| 156 | ;; End of LET | ||
| 157 | ) | ||
| 158 | |||
| 159 | ;; Test variable linkage. | ||
| 160 | (let* ((srecode-field-archive nil) | ||
| 161 | (f1 (srecode-field "Test1" :name "TEST" :start 6 :end 8)) | ||
| 162 | (f2 (srecode-field "Test2" :name "TEST" :start 28 :end 30)) | ||
| 163 | (f3 (srecode-field "Test3" :name "NOTTEST" :start 35 :end 40)) | ||
| 164 | (reg (srecode-template-inserted-region "REG" :start 4 :end 40)) | ||
| 165 | ) | ||
| 166 | (srecode-overlaid-activate reg) | ||
| 167 | |||
| 168 | (when (not (string= (srecode-overlaid-text f1) | ||
| 169 | (srecode-overlaid-text f2))) | ||
| 170 | (error "Linkage Test: Init strings are not =")) | ||
| 171 | (when (string= (srecode-overlaid-text f1) | ||
| 172 | (srecode-overlaid-text f3)) | ||
| 173 | (error "Linkage Test: Init string on dissimilar fields is now the same")) | ||
| 174 | |||
| 175 | (goto-char 7) | ||
| 176 | (insert "a") | ||
| 177 | |||
| 178 | (when (not (string= (srecode-overlaid-text f1) | ||
| 179 | (srecode-overlaid-text f2))) | ||
| 180 | (error "Linkage Test: mid-insert strings are not =")) | ||
| 181 | (when (string= (srecode-overlaid-text f1) | ||
| 182 | (srecode-overlaid-text f3)) | ||
| 183 | (error "Linkage Test: mid-insert string on dissimilar fields is now the same")) | ||
| 184 | |||
| 185 | (goto-char 9) | ||
| 186 | (insert "t") | ||
| 187 | |||
| 188 | (when (not (string= (srecode-overlaid-text f1) "iast")) | ||
| 189 | (error "Linkage Test: tail-insert failed to captured added char")) | ||
| 190 | (when (not (string= (srecode-overlaid-text f1) | ||
| 191 | (srecode-overlaid-text f2))) | ||
| 192 | (error "Linkage Test: tail-insert strings are not =")) | ||
| 193 | (when (string= (srecode-overlaid-text f1) | ||
| 194 | (srecode-overlaid-text f3)) | ||
| 195 | (error "Linkage Test: tail-insert string on dissimilar fields is now the same")) | ||
| 196 | |||
| 197 | (goto-char 6) | ||
| 198 | (insert "b") | ||
| 199 | |||
| 200 | (when (not (string= (srecode-overlaid-text f1) "biast")) | ||
| 201 | (error "Linkage Test: tail-insert failed to captured added char")) | ||
| 202 | (when (not (string= (srecode-overlaid-text f1) | ||
| 203 | (srecode-overlaid-text f2))) | ||
| 204 | (error "Linkage Test: tail-insert strings are not =")) | ||
| 205 | (when (string= (srecode-overlaid-text f1) | ||
| 206 | (srecode-overlaid-text f3)) | ||
| 207 | (error "Linkage Test: tail-insert string on dissimilar fields is now the same")) | ||
| 208 | |||
| 209 | ;; Cleanup | ||
| 210 | (srecode-delete reg) | ||
| 211 | ) | ||
| 212 | |||
| 213 | (set-buffer-modified-p nil) | ||
| 214 | |||
| 215 | (message " All field tests passed.") | ||
| 216 | )) | ||
| 217 | |||
| 218 | ;;; From srecode-document: | ||
| 219 | |||
| 220 | (require 'srecode/doc) | ||
| 221 | |||
| 222 | (defun srecode-document-function-comment-extract-test () | ||
| 223 | "Test old comment extraction. | ||
| 224 | Dump out the extracted dictionary." | ||
| 225 | (interactive) | ||
| 226 | |||
| 227 | (srecode-load-tables-for-mode major-mode) | ||
| 228 | (srecode-load-tables-for-mode major-mode 'document) | ||
| 229 | |||
| 230 | (if (not (srecode-table)) | ||
| 231 | (error "No template table found for mode %s" major-mode)) | ||
| 232 | |||
| 233 | (let* ((temp (srecode-template-get-table (srecode-table) | ||
| 234 | "function-comment" | ||
| 235 | "declaration" | ||
| 236 | 'document)) | ||
| 237 | (fcn-in (semantic-current-tag))) | ||
| 238 | |||
| 239 | (if (not temp) | ||
| 240 | (error "No templates for function comments")) | ||
| 241 | |||
| 242 | ;; Try to figure out the tag we want to use. | ||
| 243 | (when (or (not fcn-in) | ||
| 244 | (not (semantic-tag-of-class-p fcn-in 'function))) | ||
| 245 | (error "No tag of class 'function to insert comment for")) | ||
| 246 | |||
| 247 | (let ((lextok (semantic-documentation-comment-preceeding-tag fcn-in 'lex)) | ||
| 248 | ) | ||
| 249 | |||
| 250 | (when (not lextok) | ||
| 251 | (error "No comment to attempt an extraction")) | ||
| 252 | |||
| 253 | (let ((s (semantic-lex-token-start lextok)) | ||
| 254 | (e (semantic-lex-token-end lextok)) | ||
| 255 | (extract nil)) | ||
| 256 | |||
| 257 | (pulse-momentary-highlight-region s e) | ||
| 258 | |||
| 259 | ;; Extract text from the existing comment. | ||
| 260 | (setq extract (srecode-extract temp s e)) | ||
| 261 | |||
| 262 | (with-output-to-temp-buffer "*SRECODE DUMP*" | ||
| 263 | (princ "EXTRACTED DICTIONARY FOR ") | ||
| 264 | (princ (semantic-tag-name fcn-in)) | ||
| 265 | (princ "\n--------------------------------------------\n") | ||
| 266 | (srecode-dump extract)))))) | ||
diff --git a/test/cedet/tests/scopetest.cpp b/test/cedet/tests/scopetest.cpp new file mode 100644 index 00000000000..e84dd0dde06 --- /dev/null +++ b/test/cedet/tests/scopetest.cpp | |||
| @@ -0,0 +1,47 @@ | |||
| 1 | /* Test scoping rules for c++ in the analyzer. */ | ||
| 2 | |||
| 3 | namespace { | ||
| 4 | |||
| 5 | class aclass2; // Forward reference. | ||
| 6 | |||
| 7 | class aclass1 { | ||
| 8 | private: | ||
| 9 | int attrp1; | ||
| 10 | int amethodp1(int argp1); | ||
| 11 | aclass2 areference; | ||
| 12 | protected: | ||
| 13 | int attrpr1; | ||
| 14 | public: | ||
| 15 | int attr1; | ||
| 16 | int amethod1(int arg1); | ||
| 17 | }; | ||
| 18 | } | ||
| 19 | |||
| 20 | namespace { | ||
| 21 | class aclass2 : public aclass1 | ||
| 22 | { | ||
| 23 | private: | ||
| 24 | int attrp2; | ||
| 25 | int amethodp2(int argp1); | ||
| 26 | public: | ||
| 27 | aclass2(int aninitvalue); | ||
| 28 | ~aclass2(); | ||
| 29 | int attr2; | ||
| 30 | int amethod2(int arg2); | ||
| 31 | }; | ||
| 32 | } | ||
| 33 | |||
| 34 | aclass2::aclass2(init aninitvalue) | ||
| 35 | { | ||
| 36 | /* This is a comment that talks about aclass1 */ | ||
| 37 | aclass1; | ||
| 38 | } | ||
| 39 | |||
| 40 | int aclass2::amethod2(int arg2) | ||
| 41 | { | ||
| 42 | int alocalvar; | ||
| 43 | float q; | ||
| 44 | |||
| 45 | ac; | ||
| 46 | } | ||
| 47 | |||
diff --git a/test/cedet/tests/scopetest.java b/test/cedet/tests/scopetest.java new file mode 100644 index 00000000000..01825896b47 --- /dev/null +++ b/test/cedet/tests/scopetest.java | |||
| @@ -0,0 +1,25 @@ | |||
| 1 | class Foo { | ||
| 2 | |||
| 3 | public void a1() {} | ||
| 4 | |||
| 5 | class Bar { | ||
| 6 | |||
| 7 | public int a2() {} | ||
| 8 | |||
| 9 | public void b() { | ||
| 10 | a // -1- | ||
| 11 | } | ||
| 12 | |||
| 13 | class Baz { | ||
| 14 | |||
| 15 | public int a3() {} | ||
| 16 | |||
| 17 | public Baz(int a4) { | ||
| 18 | a // -2- | ||
| 19 | } | ||
| 20 | |||
| 21 | } | ||
| 22 | |||
| 23 | } | ||
| 24 | |||
| 25 | } \ No newline at end of file | ||
diff --git a/test/cedet/tests/templates.cpp b/test/cedet/tests/templates.cpp new file mode 100644 index 00000000000..5ddee820e24 --- /dev/null +++ b/test/cedet/tests/templates.cpp | |||
| @@ -0,0 +1,129 @@ | |||
| 1 | // C++ examples and requests from Klaus Berndl | ||
| 2 | |||
| 3 | // template in a unnamed namespace | ||
| 4 | namespace | ||
| 5 | { | ||
| 6 | template<typename Target, typename Source> | ||
| 7 | Target lexical_cast(Source arg) | ||
| 8 | { | ||
| 9 | std::stringstream interpreter; | ||
| 10 | Target result; | ||
| 11 | |||
| 12 | if(!(interpreter << arg) || !(interpreter >> result) || | ||
| 13 | !(interpreter >> std::ws).eof()) | ||
| 14 | throw bad_lexical_cast(); | ||
| 15 | |||
| 16 | return result; | ||
| 17 | } | ||
| 18 | } | ||
| 19 | |||
| 20 | |||
| 21 | template <class T, FOO> class Vector | ||
| 22 | { | ||
| 23 | private: | ||
| 24 | static T* v; | ||
| 25 | int sz; | ||
| 26 | |||
| 27 | public: | ||
| 28 | T& elem(int i) {return v[i];} | ||
| 29 | virtual ~Vector (); | ||
| 30 | |||
| 31 | protected: | ||
| 32 | Vector (); | ||
| 33 | }; | ||
| 34 | |||
| 35 | template <> class Vector <void*> | ||
| 36 | { | ||
| 37 | private: | ||
| 38 | void** v; | ||
| 39 | int sz; | ||
| 40 | |||
| 41 | public: | ||
| 42 | Vector (); | ||
| 43 | virtual int func1(int i); | ||
| 44 | virtual int func2(int i) = 0; | ||
| 45 | static virtual int func3(int i) = 0; | ||
| 46 | void*& elem(int i) {return v[i];} | ||
| 47 | //... | ||
| 48 | }; | ||
| 49 | |||
| 50 | // template contains namespace | ||
| 51 | typedef vector<CzkUtilities::Action*> ActionList; | ||
| 52 | |||
| 53 | // declaration of some template-types | ||
| 54 | map<XXX, Test::YYY>** map_var; | ||
| 55 | |||
| 56 | map_with_size<XXX, Test::YYY, size> map_size_var; | ||
| 57 | typedef map_with_size<XXX, Test::YYY, size> SizedMap; | ||
| 58 | |||
| 59 | map_with_10_size<XXX, Test::YYY, 10>* pMap_size10_var; | ||
| 60 | typedef map_with_10_size<XXX, Test::YYY, 10> Size10Map; | ||
| 61 | |||
| 62 | // a function which such a template-argument | ||
| 63 | void* test_function(map<ClassX, Test::ClassY, 10>* pMap); | ||
| 64 | |||
| 65 | |||
| 66 | template <class T> class Vector <T*> : private Vector <void*> | ||
| 67 | { | ||
| 68 | public: | ||
| 69 | typedef Vector <void*> Base; | ||
| 70 | |||
| 71 | Vector () : Base() {} | ||
| 72 | |||
| 73 | T*& elem(int i) {return static_cast<T*&>(Base::elem(i));} | ||
| 74 | //... | ||
| 75 | }; | ||
| 76 | |||
| 77 | // outside method implementation of a template-class | ||
| 78 | template<class T> T& Vector<T*>::elem(int i) | ||
| 79 | { | ||
| 80 | return C; | ||
| 81 | } | ||
| 82 | |||
| 83 | // same but qualified with a namespace Testnamespace | ||
| 84 | template<class T> T& Testnamespace::Vector<T*>::elem(int i) | ||
| 85 | { | ||
| 86 | return C; | ||
| 87 | } | ||
| 88 | |||
| 89 | // function templates with keyword typename | ||
| 90 | template<typename Target, typename Source> | ||
| 91 | Target lexical_cast(Source arg) | ||
| 92 | { | ||
| 93 | std::stringstream interpreter; | ||
| 94 | Target result; | ||
| 95 | |||
| 96 | if(!(interpreter << arg) || !(interpreter >> result) || | ||
| 97 | !(interpreter >> std::ws).eof()) | ||
| 98 | throw bad_lexical_cast(); | ||
| 99 | |||
| 100 | return result; | ||
| 101 | } | ||
| 102 | |||
| 103 | template<class T> | ||
| 104 | static | ||
| 105 | typename T::_ptr_type | ||
| 106 | getService(const std::string& pServiceName, const int pRetries=20) | ||
| 107 | { | ||
| 108 | return T::_narrow(getServiceObject(pServiceName, pRetries)); | ||
| 109 | } | ||
| 110 | |||
| 111 | // function template declaration | ||
| 112 | template<class T> void sort(vector<T>&); | ||
| 113 | // complex function template definition | ||
| 114 | template<class T, class S, const NamespaceY::ClassX<TestClass, &s> volatile ***&i> | ||
| 115 | map<ClassY, ClassX, 10> | ||
| 116 | sort(const vector<T>& v) | ||
| 117 | { | ||
| 118 | return; | ||
| 119 | } | ||
| 120 | |||
| 121 | // variable declarations of template-types | ||
| 122 | foo<TClass, Testnamespace::XClass, i> *bar1; | ||
| 123 | foo<TClass, Testnamespace::XClass, **&i> *bar2; | ||
| 124 | foo<TClass, Testnamespace::XClass, *Namespace::ClassX::i> bar3; | ||
| 125 | foo<0> bar0; | ||
| 126 | |||
| 127 | class SomeName; | ||
| 128 | class OtherName; | ||
| 129 | |||
diff --git a/test/cedet/tests/test.c b/test/cedet/tests/test.c new file mode 100644 index 00000000000..3146bbcc53a --- /dev/null +++ b/test/cedet/tests/test.c | |||
| @@ -0,0 +1,222 @@ | |||
| 1 | /* Test file for C language. | ||
| 2 | * Attempt to include as many aspects of the C language as possible. | ||
| 3 | * | ||
| 4 | * $Id: test.c,v 1.1.2.1 2009/09/20 04:00:17 cyd Exp $ | ||
| 5 | * | ||
| 6 | */ | ||
| 7 | /* types of include files */ | ||
| 8 | #include "includeme1.h" | ||
| 9 | #include <includeme2.h> | ||
| 10 | #include <subdir/includeme3.h> | ||
| 11 | #include <includeme.notanhfile> | ||
| 12 | #include <stdlib.h> | ||
| 13 | #include <cmath> | ||
| 14 | |||
| 15 | #if 0 | ||
| 16 | int dont_show_function() | ||
| 17 | { | ||
| 18 | } | ||
| 19 | #endif | ||
| 20 | |||
| 21 | /* Global types */ | ||
| 22 | struct mystruct1 { | ||
| 23 | int slot11; | ||
| 24 | char slot12; | ||
| 25 | float slot13; | ||
| 26 | }; | ||
| 27 | |||
| 28 | struct mystruct2 { | ||
| 29 | int slot21; | ||
| 30 | char slot22; | ||
| 31 | float slot23; | ||
| 32 | } var_of_type_mystruct2; | ||
| 33 | |||
| 34 | struct { | ||
| 35 | int slot31; | ||
| 36 | char slot32; | ||
| 37 | float slot33; | ||
| 38 | } var_of_anonymous_struct; | ||
| 39 | |||
| 40 | typedef struct mystruct1 typedef_of_mystruct1; | ||
| 41 | typedef struct mystruct1 *typedef_of_pointer_mystruct1; | ||
| 42 | typedef struct { int slot_a; } typedef_of_anonymous_struct; | ||
| 43 | typedef struct A { | ||
| 44 | } B; | ||
| 45 | |||
| 46 | typedef struct mystruct1 td1, td2; | ||
| 47 | |||
| 48 | union myunion1 { | ||
| 49 | int slot41; | ||
| 50 | char slot42; | ||
| 51 | float slot43; | ||
| 52 | }; | ||
| 53 | |||
| 54 | union myunion2 { | ||
| 55 | int slot51; | ||
| 56 | char slot52; | ||
| 57 | float slot53; | ||
| 58 | } var_of_type_myunion2; | ||
| 59 | |||
| 60 | struct { | ||
| 61 | int slot61; | ||
| 62 | char slot72; | ||
| 63 | float slot83; | ||
| 64 | } var_of_anonymous_union; | ||
| 65 | |||
| 66 | typedef union myunion1 typedef_of_myunion1; | ||
| 67 | typedef union myunion1 *typedef_of_pointer_myunion1; | ||
| 68 | typedef union { int slot_a; } typedef_of_anonymous_union; | ||
| 69 | |||
| 70 | enum myenum1 { enum11 = 1, enum12 }; | ||
| 71 | enum myenum2 { enum21, enum22 = 2 } var_of_type_myenum2; | ||
| 72 | enum { enum31, enum32 } var_of_anonymous_enum; | ||
| 73 | |||
| 74 | typedef enum myenum1 typedef_of_myenum1; | ||
| 75 | typedef enum myenum1 *typedef_of_pointer_myenum1; | ||
| 76 | typedef enum { enum_a = 3, enum_b } typedef_of_anonymous_enum; | ||
| 77 | |||
| 78 | typedef int typedef_of_int; | ||
| 79 | |||
| 80 | /* Here are some simpler variable types */ | ||
| 81 | int var1; | ||
| 82 | int varbit1:1; | ||
| 83 | char var2; | ||
| 84 | float var3; | ||
| 85 | mystruct1 var3; | ||
| 86 | struct mystruct1 var4; | ||
| 87 | union myunion1 var5; | ||
| 88 | enum myenum1 var6; | ||
| 89 | |||
| 90 | char *varp1; | ||
| 91 | char **varp2; | ||
| 92 | char varv1[1]; | ||
| 93 | char varv2[1][2]; | ||
| 94 | |||
| 95 | char *varpa1 = "moose"; | ||
| 96 | struct mystruct2 vara2 = { 1, 'a', 0.0 }; | ||
| 97 | enum myenum1 vara3 = enum11; | ||
| 98 | int vara4 = (int)0.0; | ||
| 99 | int vara5 = funcall(); | ||
| 100 | |||
| 101 | int mvar1, mvar2, mvar3; | ||
| 102 | char *mvarp1, *mvarp2, *mvarp3; | ||
| 103 | char *mvarpa1 = 'a', *mvarpa2 = 'b', *mvarpa3 = 'c'; | ||
| 104 | char mvaras1[10], mvaras2[12][13], *mvaras3 = 'd'; | ||
| 105 | |||
| 106 | static register const unsigned int tmvar1; | ||
| 107 | |||
| 108 | #define MACRO1 1 | ||
| 109 | #define MACRO2(foo) (1+foo) | ||
| 110 | |||
| 111 | /* Here are some function prototypes */ | ||
| 112 | |||
| 113 | /* This is legal, but I decided not to support inferred integer | ||
| 114 | * types on functions and variables. | ||
| 115 | */ | ||
| 116 | fun0(); | ||
| 117 | int funp1(); | ||
| 118 | char funp2(int arg11); | ||
| 119 | float funp3(char arg21, char arg22); | ||
| 120 | struct mystrct1 funp4(struct mystruct2 arg31, union myunion2 arg32); | ||
| 121 | enum myenum1 funp5(char *arg41, union myunion1 *arg42); | ||
| 122 | |||
| 123 | char funpp1 __P(char argp1, struct mystruct2 argp2, char *arg4p); | ||
| 124 | |||
| 125 | int fun1(); | ||
| 126 | |||
| 127 | /* Here is a function pointer */ | ||
| 128 | int (*funcptr)(int a, int b); | ||
| 129 | |||
| 130 | /* Function Definitions */ | ||
| 131 | |||
| 132 | /* This is legal, but I decided not to support inferred integer | ||
| 133 | * types on functions and variables. | ||
| 134 | */ | ||
| 135 | fun0() | ||
| 136 | { | ||
| 137 | int sv = 0; | ||
| 138 | } | ||
| 139 | |||
| 140 | int fun1 () | ||
| 141 | { | ||
| 142 | int sv = 1; | ||
| 143 | } | ||
| 144 | |||
| 145 | int fun1p1 (void) | ||
| 146 | { | ||
| 147 | int sv = 1; | ||
| 148 | } | ||
| 149 | |||
| 150 | char fun2(int arg_11) | ||
| 151 | { | ||
| 152 | char sv = 2; | ||
| 153 | } | ||
| 154 | |||
| 155 | float fun3(char arg_21, char arg_22) | ||
| 156 | { | ||
| 157 | char sv = 3; | ||
| 158 | } | ||
| 159 | |||
| 160 | struct mystrct1 fun4(struct mystruct2 arg31, union myunion2 arg32) | ||
| 161 | { | ||
| 162 | sv = 4; | ||
| 163 | } | ||
| 164 | |||
| 165 | enum myenum1 fun5(char *arg41, union myunion1 *arg42) | ||
| 166 | { | ||
| 167 | sv = 5; | ||
| 168 | } | ||
| 169 | |||
| 170 | /* Functions with K&R syntax. */ | ||
| 171 | struct mystrct1 funk1(arg_31, arg_32) | ||
| 172 | struct mystruct2 arg_31; | ||
| 173 | union myunion2 arg32; | ||
| 174 | { | ||
| 175 | sv = 4; | ||
| 176 | } | ||
| 177 | |||
| 178 | enum myenum1 *funk2(arg_41, arg_42) | ||
| 179 | char *arg_41; | ||
| 180 | union myunion1 *arg_42; | ||
| 181 | { | ||
| 182 | sv = 5; | ||
| 183 | |||
| 184 | if(foo) { | ||
| 185 | } | ||
| 186 | } | ||
| 187 | |||
| 188 | int funk3(arg_51, arg_53) | ||
| 189 | int arg_51; | ||
| 190 | char arg_53; | ||
| 191 | { | ||
| 192 | char q = 'a'; | ||
| 193 | int sv = 6; | ||
| 194 | td1 ms1; | ||
| 195 | enum myenum1 testconst; | ||
| 196 | |||
| 197 | /* Function argument analysis */ | ||
| 198 | funk3(ms1.slot11, arg_53 ); | ||
| 199 | sv = 7; | ||
| 200 | |||
| 201 | /* Slot deref on assignee */ | ||
| 202 | ms1.slot11 = s; | ||
| 203 | |||
| 204 | /* Enum/const completion */ | ||
| 205 | testconst = e; | ||
| 206 | |||
| 207 | /* Bad var/slot and param */ | ||
| 208 | blah.notafunction(moose); | ||
| 209 | |||
| 210 | /* Print something. */ | ||
| 211 | printf("Moose", ); | ||
| 212 | |||
| 213 | tan(); | ||
| 214 | } | ||
| 215 | |||
| 216 | int funk4_fixme(arg_61, arg_62) | ||
| 217 | int arg_61, arg_62; | ||
| 218 | { | ||
| 219 | |||
| 220 | } | ||
| 221 | |||
| 222 | /* End of C tests */ | ||
diff --git a/test/cedet/tests/test.cpp b/test/cedet/tests/test.cpp new file mode 100644 index 00000000000..43887b084a1 --- /dev/null +++ b/test/cedet/tests/test.cpp | |||
| @@ -0,0 +1,593 @@ | |||
| 1 | /* Test file for C++ language. | ||
| 2 | * Attempt to include as many aspects of the C++ language as possible. | ||
| 3 | * Do not include things tested in test.c since that shares the | ||
| 4 | * same language. | ||
| 5 | * | ||
| 6 | * $Id: test.cpp,v 1.1.2.1 2009/09/20 04:00:17 cyd Exp $ | ||
| 7 | * | ||
| 8 | */ | ||
| 9 | |||
| 10 | /* An include test */ | ||
| 11 | #include <stdio.h> | ||
| 12 | |||
| 13 | #include <cmath> | ||
| 14 | |||
| 15 | #include "c++-test.hh" | ||
| 16 | |||
| 17 | #include <c++-test.hh> | ||
| 18 | |||
| 19 | double var1 = 1.2; | ||
| 20 | |||
| 21 | int simple1(int a) { | ||
| 22 | |||
| 23 | } | ||
| 24 | |||
| 25 | struct foo1 { | ||
| 26 | int test; | ||
| 27 | }; | ||
| 28 | |||
| 29 | struct foo2 : public foo1 { | ||
| 30 | const int foo21(int a, int b); | ||
| 31 | const int foo22(int a, int b) { return 1 } | ||
| 32 | }; | ||
| 33 | |||
| 34 | /* Classes */ | ||
| 35 | class class1 { | ||
| 36 | private: | ||
| 37 | int var11; | ||
| 38 | struct foo1 var12; | ||
| 39 | public: | ||
| 40 | int p_var11; | ||
| 41 | struct foo p_var12; | ||
| 42 | }; | ||
| 43 | |||
| 44 | class i_class1 : public class1 { | ||
| 45 | private: | ||
| 46 | int var11; | ||
| 47 | struct foo var12; | ||
| 48 | public: | ||
| 49 | int p_var11; | ||
| 50 | struct foo p_var12; | ||
| 51 | }; | ||
| 52 | |||
| 53 | class class2 { | ||
| 54 | private: | ||
| 55 | int var21; | ||
| 56 | struct foo var22; | ||
| 57 | public: | ||
| 58 | int p_var21; | ||
| 59 | struct foo p_var22; | ||
| 60 | }; | ||
| 61 | |||
| 62 | class i_class2 : public class1, public class2 { | ||
| 63 | private: | ||
| 64 | int var21; | ||
| 65 | struct foo var22; | ||
| 66 | protected: | ||
| 67 | int pt_var21; | ||
| 68 | public: | ||
| 69 | int p_var21; | ||
| 70 | struct foo p_var22; | ||
| 71 | }; | ||
| 72 | |||
| 73 | class class3 { | ||
| 74 | /* A class with strange things in it */ | ||
| 75 | public: | ||
| 76 | class3(); /* A constructor */ | ||
| 77 | enum embedded_foo_enum { | ||
| 78 | a, b, c | ||
| 79 | } embed1; | ||
| 80 | struct embedded_bar_struct { | ||
| 81 | int a; | ||
| 82 | int b; | ||
| 83 | } embed2; | ||
| 84 | class embedded_baz_class { | ||
| 85 | embedded_baz_class(); | ||
| 86 | ~embedded_baz_class(); | ||
| 87 | } embed3; | ||
| 88 | ~class3(); /* destructor */ | ||
| 89 | |||
| 90 | /* Methods */ | ||
| 91 | int method_for_class3(int a, char b); | ||
| 92 | |||
| 93 | int inline_method(int c) { return c; } | ||
| 94 | |||
| 95 | /* Operators */ | ||
| 96 | class3& operator^= (const class3& something); | ||
| 97 | |||
| 98 | /* Funny declmods */ | ||
| 99 | const class3 * const method_const_ptr_ptr(const int * const argconst) const = 0; | ||
| 100 | }; | ||
| 101 | |||
| 102 | class3::class3() | ||
| 103 | { | ||
| 104 | /* Constructor outside the definition. */ | ||
| 105 | } | ||
| 106 | |||
| 107 | int class3::method_for_class3(int a, char b) | ||
| 108 | { | ||
| 109 | } | ||
| 110 | |||
| 111 | int class3::method1_for_class3( int a, int &b) | ||
| 112 | { | ||
| 113 | int cvariablename; | ||
| 114 | class3 fooy[]; | ||
| 115 | class3 moose = new class3; | ||
| 116 | |||
| 117 | // Complktion testing line should find external members. | ||
| 118 | a = fooy[1].me ; | ||
| 119 | b = cv ; | ||
| 120 | |||
| 121 | if (fooy.emb) { | ||
| 122 | simple1(c); | ||
| 123 | } | ||
| 124 | |||
| 125 | cos(10); | ||
| 126 | abs(10); | ||
| 127 | |||
| 128 | return 1; | ||
| 129 | } | ||
| 130 | |||
| 131 | char class3::method2_for_class3( int a, int b) throw ( exception1 ) | ||
| 132 | { | ||
| 133 | return 'a'; | ||
| 134 | } | ||
| 135 | |||
| 136 | void *class3::method3_for_class3( int a, int b) throw ( exception1, exception2 ) | ||
| 137 | { | ||
| 138 | int q = a; | ||
| 139 | return "Moose"; | ||
| 140 | } | ||
| 141 | |||
| 142 | void *class3::method31_for_class3( int a, int b) throw ( ) | ||
| 143 | { | ||
| 144 | int q = a; | ||
| 145 | return "Moose"; | ||
| 146 | } | ||
| 147 | |||
| 148 | void *class3::method4_for_class3( int a, int b) reentrant | ||
| 149 | { | ||
| 150 | class3 ct; | ||
| 151 | |||
| 152 | ct.method5_for_class3(1,a); | ||
| 153 | |||
| 154 | pritf(); | ||
| 155 | } | ||
| 156 | |||
| 157 | /* | ||
| 158 | * A method on class3. | ||
| 159 | */ | ||
| 160 | void *class3::method5_for_class3( int a, int b) const | ||
| 161 | { | ||
| 162 | } | ||
| 163 | |||
| 164 | /* | ||
| 165 | * Namespace parsing tests | ||
| 166 | */ | ||
| 167 | namespace NS { | ||
| 168 | class class_in_namespace { | ||
| 169 | int equiv(const NS::class_in_namespace *) const; | ||
| 170 | }; | ||
| 171 | } | ||
| 172 | |||
| 173 | int NS::class_in_namespace::equiv(const NS::class_in_namespace *cin) const | ||
| 174 | { | ||
| 175 | return 0; | ||
| 176 | } | ||
| 177 | |||
| 178 | // Stuff Klaus found. | ||
| 179 | // Inheritance w/out a specifying for public. | ||
| 180 | class class4 : class1 { | ||
| 181 | // Pure virtual methods. | ||
| 182 | void virtual print () const = 0; | ||
| 183 | |||
| 184 | public: | ||
| 185 | // The whacky constructor type | ||
| 186 | class4() | ||
| 187 | try : class1(args) | ||
| 188 | { | ||
| 189 | // constructor body | ||
| 190 | } | ||
| 191 | catch () | ||
| 192 | { | ||
| 193 | |||
| 194 | } | ||
| 195 | |||
| 196 | |||
| 197 | }; | ||
| 198 | |||
| 199 | class class5 : public virtual class4 { | ||
| 200 | // Virtual inheritance | ||
| 201 | }; | ||
| 202 | |||
| 203 | class class6 : class1 { | ||
| 204 | // Mutable | ||
| 205 | mutable int i; | ||
| 206 | }; | ||
| 207 | |||
| 208 | /* Namespaces */ | ||
| 209 | namespace namespace1 { | ||
| 210 | void ns_method1() { } | ||
| 211 | |||
| 212 | class n_class1 { | ||
| 213 | public: | ||
| 214 | void method11(int a) { } | ||
| 215 | }; | ||
| 216 | |||
| 217 | /* This shouldn't parse due to missing semicolon. */ | ||
| 218 | class _n_class2 : public n_class1 { | ||
| 219 | void n_c2_method1(int a, int b) { } | ||
| 220 | }; | ||
| 221 | |||
| 222 | // Macros in the namespace | ||
| 223 | #define NSMACRO 1 | ||
| 224 | |||
| 225 | // Template in the namespace | ||
| 226 | template<class T> T nsti1(const Foo& foo); | ||
| 227 | template<> int nsti1<int>(const Foo& foo); | ||
| 228 | |||
| 229 | } | ||
| 230 | |||
| 231 | namespace namespace2 { | ||
| 232 | |||
| 233 | using namespace1::n_class1; | ||
| 234 | |||
| 235 | } | ||
| 236 | |||
| 237 | /* Initializers */ | ||
| 238 | void tinitializers1(): inita1(False), | ||
| 239 | inita2(False) | ||
| 240 | { | ||
| 241 | inita1= 1; | ||
| 242 | } | ||
| 243 | |||
| 244 | /* How about Extern C type things. */ | ||
| 245 | int funny_prototype(int ,int b,float c) | ||
| 246 | { | ||
| 247 | |||
| 248 | } | ||
| 249 | |||
| 250 | extern "C" | ||
| 251 | int extern_c_1(int a, int b) | ||
| 252 | { | ||
| 253 | |||
| 254 | funny_prototype(1,2,3.4); | ||
| 255 | |||
| 256 | printf("Moose", ); | ||
| 257 | |||
| 258 | return 1; | ||
| 259 | } | ||
| 260 | |||
| 261 | extern "C" { | ||
| 262 | |||
| 263 | int extern_c_2(int a, int b) | ||
| 264 | { | ||
| 265 | return 1; | ||
| 266 | } | ||
| 267 | |||
| 268 | } | ||
| 269 | |||
| 270 | // Some operator stuff | ||
| 271 | class Action | ||
| 272 | { | ||
| 273 | // Problems!! operator() and operator[] can not be parsed with semantic | ||
| 274 | // 1.4.2 but with latest c.by | ||
| 275 | virtual void operator()(int i, char *p ) = 0; | ||
| 276 | virtual String& operator[]() = 0; | ||
| 277 | virtual void operator!() = 0; | ||
| 278 | virtual void operator->() = 0; | ||
| 279 | virtual T& operator+=(); | ||
| 280 | virtual T& operator*(); | ||
| 281 | virtual T& operator*=(); | ||
| 282 | }; | ||
| 283 | |||
| 284 | // class with namespace qualified parents | ||
| 285 | class Multiinherit : public virtual POA::Parent, | ||
| 286 | public virtual POA::Parent1, | ||
| 287 | Parent | ||
| 288 | { | ||
| 289 | private: | ||
| 290 | int i; | ||
| 291 | |||
| 292 | public: | ||
| 293 | Multiinherit(); | ||
| 294 | ~Multiinherit(); | ||
| 295 | |||
| 296 | // method with a list of qualified exceptions | ||
| 297 | void* throwtest() | ||
| 298 | throw(Exception0, | ||
| 299 | Testnamespace::Exception1, | ||
| 300 | Testnamespace::Excpetion2, | ||
| 301 | Testnamespace::testnamespace1::Exception3); | ||
| 302 | |||
| 303 | }; | ||
| 304 | |||
| 305 | void* | ||
| 306 | Multiinherit::throwtest() | ||
| 307 | throw (Exception0, | ||
| 308 | Testnamespace::Exception1, | ||
| 309 | Testnamespace::Excpetion2, | ||
| 310 | Testnamespace::testnamespace1::Exception3) | ||
| 311 | { | ||
| 312 | return; | ||
| 313 | } | ||
| 314 | |||
| 315 | // Jens Rock <jens.rock@asamnet.de>: Nested classes or structs defined | ||
| 316 | // outside of the containing class/struct. | ||
| 317 | class container | ||
| 318 | { | ||
| 319 | public: | ||
| 320 | struct contained; | ||
| 321 | container(); | ||
| 322 | ~container(); | ||
| 323 | }; | ||
| 324 | |||
| 325 | struct container::contained | ||
| 326 | { | ||
| 327 | public: | ||
| 328 | contained(); | ||
| 329 | ~contained(); | ||
| 330 | }; | ||
| 331 | |||
| 332 | /* | ||
| 333 | * Ok, how about some template stuff. | ||
| 334 | */ | ||
| 335 | template <class CT, class container = vector<CT> > | ||
| 336 | const CT& max (const CT& a, const CT& b) | ||
| 337 | { | ||
| 338 | return a < b ? b : a; | ||
| 339 | } | ||
| 340 | |||
| 341 | // Arne Schmitz found this one | ||
| 342 | std::vector<int> &a, &b, &c; | ||
| 343 | |||
| 344 | class TemplateUsingClass | ||
| 345 | { | ||
| 346 | typedef TestClassMap::iterator iterator; | ||
| 347 | typedef map<long, long> TestClassMap; | ||
| 348 | |||
| 349 | // typedefs with const and volatile | ||
| 350 | typedef const map<long, long> const_TestClassMap; | ||
| 351 | typedef TestClassMap<string>::iterator volatile volatile_iterator; | ||
| 352 | |||
| 353 | map<int, int> mapclassvarthingy; | ||
| 354 | }; | ||
| 355 | |||
| 356 | template<class T> T ti1(const Foo& foo); | ||
| 357 | template<> int ti1<int>(const Foo& foo); | ||
| 358 | |||
| 359 | |||
| 360 | // ----------------------------------- | ||
| 361 | // Now some namespace and related stuff | ||
| 362 | // ----------------------------------- | ||
| 363 | |||
| 364 | using CORBA::LEX::get_token; | ||
| 365 | using Namespace1; | ||
| 366 | |||
| 367 | using namespace POA::std; | ||
| 368 | using namespace Test; | ||
| 369 | |||
| 370 | |||
| 371 | |||
| 372 | namespace Parser | ||
| 373 | { | ||
| 374 | namespace | ||
| 375 | { | ||
| 376 | using Lexer::get_test; | ||
| 377 | string str = ""; | ||
| 378 | } | ||
| 379 | |||
| 380 | namespace XXX | ||
| 381 | { | ||
| 382 | |||
| 383 | class Foobar : public virtual POA::Parent, | ||
| 384 | public virtual POA::Parent1, | ||
| 385 | private POA::list<fact>, | ||
| 386 | private map<string> | ||
| 387 | { | ||
| 388 | ini i; | ||
| 389 | list <shared_ptr<item> >::const_iterator l; | ||
| 390 | public: | ||
| 391 | |||
| 392 | Foobar(); | ||
| 393 | ~Foobar(); | ||
| 394 | }; | ||
| 395 | } | ||
| 396 | |||
| 397 | |||
| 398 | void test_function(int i); | ||
| 399 | |||
| 400 | }; | ||
| 401 | |||
| 402 | // unnamed namespaces - even nested | ||
| 403 | namespace | ||
| 404 | { | ||
| 405 | namespace | ||
| 406 | { | ||
| 407 | using Lexer::get_test; | ||
| 408 | string str = ""; | ||
| 409 | } | ||
| 410 | |||
| 411 | // some builtin types | ||
| 412 | long long ll = 0; | ||
| 413 | long double d = 0.0; | ||
| 414 | unsigned test; | ||
| 415 | unsigned long int **uli = 0; | ||
| 416 | signed si = 0; | ||
| 417 | signed short ss = 0; | ||
| 418 | short int i = 0; | ||
| 419 | long int li = 0; | ||
| 420 | |||
| 421 | // expressions with namespace/class-qualifyiers | ||
| 422 | ORB_var cGlobalOrb = ORB::_nil(); | ||
| 423 | ORB_var1 cGlobalOrb1 = ORB::_test; | ||
| 424 | |||
| 425 | class Testclass | ||
| 426 | { | ||
| 427 | #define TEST 0 | ||
| 428 | ini i; | ||
| 429 | |||
| 430 | public: | ||
| 431 | |||
| 432 | Testclass(); | ||
| 433 | ~Testclass(); | ||
| 434 | }; | ||
| 435 | |||
| 436 | static void test_function(unsigned int i); | ||
| 437 | |||
| 438 | }; | ||
| 439 | |||
| 440 | |||
| 441 | // outside method implementations which should be grouped to type Test | ||
| 442 | XXX& | ||
| 443 | Test::waiting() | ||
| 444 | { | ||
| 445 | return; | ||
| 446 | } | ||
| 447 | |||
| 448 | void | ||
| 449 | Test::print() | ||
| 450 | { | ||
| 451 | return; | ||
| 452 | } | ||
| 453 | |||
| 454 | // outside method implementations with namespaces which should be grouped to | ||
| 455 | // their complete (incl. namespace) types | ||
| 456 | void* | ||
| 457 | Parser::XXX::Foobar::wait(int i, const char const * const * p) | ||
| 458 | { | ||
| 459 | return; | ||
| 460 | } | ||
| 461 | |||
| 462 | void* | ||
| 463 | Namespace1::Test::wait1(int i) | ||
| 464 | { | ||
| 465 | return; | ||
| 466 | } | ||
| 467 | |||
| 468 | int | ||
| 469 | Namespace1::Test::waiting(int i) | ||
| 470 | { | ||
| 471 | return; | ||
| 472 | } | ||
| 473 | |||
| 474 | // a class with some outside implementations which should all be grouped to | ||
| 475 | // this class declaration | ||
| 476 | class ClassWithExternals | ||
| 477 | { | ||
| 478 | private: | ||
| 479 | int i; | ||
| 480 | |||
| 481 | public: | ||
| 482 | ClassWithExternals(); | ||
| 483 | ~ClassWithExternals(); | ||
| 484 | void non_nil(); | ||
| 485 | }; | ||
| 486 | |||
| 487 | |||
| 488 | // Foobar is not displayed; seems that semantic tries to add this to the class | ||
| 489 | // Foobar but can not find/display it, because contained in the namespace above. | ||
| 490 | void | ||
| 491 | Foobar::non_nil() | ||
| 492 | { | ||
| 493 | return; | ||
| 494 | } | ||
| 495 | |||
| 496 | // are correctly grouped to the ClassWithExternals class | ||
| 497 | void | ||
| 498 | ClassWithExternals::non_nil() | ||
| 499 | { | ||
| 500 | String s = "lödfjg dlfgkdlfkgjdl"; | ||
| 501 | return; | ||
| 502 | } | ||
| 503 | |||
| 504 | ClassWithExternals::ClassWithExternals() | ||
| 505 | { | ||
| 506 | return; | ||
| 507 | } | ||
| 508 | |||
| 509 | void | ||
| 510 | ClassWithExternals::~ClassWithExternals() | ||
| 511 | { | ||
| 512 | return; | ||
| 513 | } | ||
| 514 | |||
| 515 | |||
| 516 | // ------------------------------- | ||
| 517 | // Now some macro and define stuff | ||
| 518 | // ------------------------------- | ||
| 519 | |||
| 520 | #define TEST 0 | ||
| 521 | #define TEST1 "String" | ||
| 522 | |||
| 523 | // The first backslash makes this macro unmatched syntax with semantic 1.4.2! | ||
| 524 | // With flexing \+newline as nothing all is working fine! | ||
| 525 | #define MZK_ENTER(METHOD) \ | ||
| 526 | { \ | ||
| 527 | CzkMethodLog lMethodLog(METHOD,"Framework");\ | ||
| 528 | } | ||
| 529 | |||
| 530 | #define ZK_ASSERTM(METHOD,ASSERTION,MESSAGE) \ | ||
| 531 | { if(!(ASSERTION))\ | ||
| 532 | {\ | ||
| 533 | std::ostringstream lMesgStream; \ | ||
| 534 | lMesgStream << "Assertion failed: " \ | ||
| 535 | << MESSAGE; \ | ||
| 536 | CzkLogManager::doLog(CzkLogManager::FATAL,"",METHOD, \ | ||
| 537 | "Assert",lMesgStream); \ | ||
| 538 | assert(ASSERTION);\ | ||
| 539 | }\ | ||
| 540 | } | ||
| 541 | |||
| 542 | // Test if not newline-backslashes are handled correctly | ||
| 543 | string s = "My \"quoted\" string"; | ||
| 544 | |||
| 545 | // parsed fine as macro | ||
| 546 | #define FOO (arg) method(arg, "foo"); | ||
| 547 | |||
| 548 | // With semantic 1.4.2 this parsed as macro BAR *and* function method. | ||
| 549 | // With latest c.bnf at least one-liner macros can be parsed correctly. | ||
| 550 | #define BAR (arg) CzkMessageLog method(arg, "bar"); | ||
| 551 | |||
| 552 | // some const and volatile stuff | ||
| 553 | char * p1 = "Hello"; // 1. variable Pointer, variable Data | ||
| 554 | const char * p2 = "Hello"; // 2. variable pointer, constant data | ||
| 555 | char * const p3 = "Hello"; // 3. constant pointer, variable data | ||
| 556 | const char * const p4 = "Hello"; // 4. constant pointer, constant data | ||
| 557 | |||
| 558 | // Case 2 and 4 can exchange first "const" and "char" | ||
| 559 | char const * p21 = "Hello"; // variable pointer, constant data | ||
| 560 | char const * const p41 = "Hello"; // constant pointer, constant data | ||
| 561 | |||
| 562 | char volatile a = 0; // a volatile char | ||
| 563 | void foo(bar const &arg); // a reference to a const bar | ||
| 564 | int foobar(bar const * const p); // a const pointer to a const bar | ||
| 565 | int foobar(bar const volatile * const p); // a const pointer to a const bar | ||
| 566 | int foobar3(char* p); // a const pointer to a const bar | ||
| 567 | |||
| 568 | // Should not be parsed because this is invalid code | ||
| 569 | int const & const r3 = i; | ||
| 570 | |||
| 571 | boolean i = 0; | ||
| 572 | boolean & r1 = i; | ||
| 573 | boolean const & r2 = i; | ||
| 574 | |||
| 575 | // const * sequences can be very long in C++ ;-) | ||
| 576 | char const * const * const * const * ppp; | ||
| 577 | |||
| 578 | // complex function declarationen with named pointer-arguments | ||
| 579 | const char** foobar1(volatile char const * const **p); | ||
| 580 | const char** foobar11(volatile Test::Namespace::Char<char*> const * const **p); | ||
| 581 | |||
| 582 | // complex function declarationen with unnamed pointer-arguments | ||
| 583 | const char* foobar2(const char***); | ||
| 584 | const char* foobar21(const Test::Namespace::Char<char>***); | ||
| 585 | |||
| 586 | // string literal parsing even with wchar_t | ||
| 587 | char const *p = "string1"; | ||
| 588 | char const *q = "string1" "str\"ing2" "string3"; | ||
| 589 | wchar_t testc = L'a'; | ||
| 590 | |||
| 591 | wchar_t const *wp = L"string with a \" in it"; | ||
| 592 | wchar_t const *wq = L"string \n\t\"test" L"string2"; | ||
| 593 | wchar_t const *wr = L"string L"; | ||
diff --git a/test/cedet/tests/test.el b/test/cedet/tests/test.el new file mode 100644 index 00000000000..2997b687677 --- /dev/null +++ b/test/cedet/tests/test.el | |||
| @@ -0,0 +1,141 @@ | |||
| 1 | ;; Test file for Emacs Lisp. | ||
| 2 | ;; Attempt to include as many aspects of Emacs Lisp as possible. | ||
| 3 | ;; | ||
| 4 | |||
| 5 | ;;; Require | ||
| 6 | ;; | ||
| 7 | (require 'semantic) | ||
| 8 | (require 'eieio "../eieio") | ||
| 9 | |||
| 10 | ;; tags encapsulated in eval-when-compile and eval-and-compile | ||
| 11 | ;; should be expanded out into the outer environment. | ||
| 12 | (eval-when-compile | ||
| 13 | (require 'semantic-imenu) | ||
| 14 | ) | ||
| 15 | |||
| 16 | (eval-and-compile | ||
| 17 | (defconst const-1 nil) | ||
| 18 | (defun function-1 (arg) | ||
| 19 | nil) | ||
| 20 | ) | ||
| 21 | |||
| 22 | ;;; Functions | ||
| 23 | ;; | ||
| 24 | (defun a-defun (arg1 arg2 &optional arg3) | ||
| 25 | "doc a" | ||
| 26 | nil) | ||
| 27 | |||
| 28 | (defun a-defun-interactive (arg1 arg2 &optional arg3) | ||
| 29 | "doc a that is a command" | ||
| 30 | (interactive "R") | ||
| 31 | nil) | ||
| 32 | |||
| 33 | (defun* a-defun* (arg1 arg2 &optional arg3) | ||
| 34 | "doc a*" | ||
| 35 | nil) | ||
| 36 | |||
| 37 | (defsubst a-defsubst (arg1 arg2 &optional arg3) | ||
| 38 | "doc a-subst" | ||
| 39 | nil) | ||
| 40 | |||
| 41 | (defmacro a-defmacro (arg1 arg2 &optional arg3) | ||
| 42 | "doc a-macro" | ||
| 43 | nil) | ||
| 44 | |||
| 45 | (define-overload a-overload (arg) | ||
| 46 | "doc a-overload" | ||
| 47 | nil) | ||
| 48 | |||
| 49 | ;;; Methods | ||
| 50 | ;; | ||
| 51 | (defmethod a-method ((obj some-class) &optional arg2) | ||
| 52 | "Doc String for a method." | ||
| 53 | (call-next-method)) | ||
| 54 | |||
| 55 | (defgeneric a-generic (arg1 arg2) | ||
| 56 | "General description of a-generic.") | ||
| 57 | |||
| 58 | ;;; Advice | ||
| 59 | ;; | ||
| 60 | (defadvice existing-function-to-advise (around test activate) | ||
| 61 | "Do something special to this fcn." | ||
| 62 | (ad-do-it)) | ||
| 63 | |||
| 64 | ;;; Variables | ||
| 65 | ;; | ||
| 66 | (defvar a-defvar (cons 1 2) | ||
| 67 | "Variable a") | ||
| 68 | |||
| 69 | (defvar a-defvar-star (cons 1 2) | ||
| 70 | "*User visible var a") | ||
| 71 | |||
| 72 | (defconst a-defconst 'a "var doc const") | ||
| 73 | |||
| 74 | (defcustom a-defcustom nil | ||
| 75 | "*doc custom" | ||
| 76 | :group 'a-defgroup | ||
| 77 | :type 'boolean) | ||
| 78 | |||
| 79 | (defface a-defface 'bold | ||
| 80 | "A face that is bold.") | ||
| 81 | |||
| 82 | (defimage ezimage-page-minus | ||
| 83 | ((:type xpm :file "page-minus.xpm" :ascent center)) | ||
| 84 | "Image used for open files with stuff in them.") | ||
| 85 | |||
| 86 | ;;; Autoloads | ||
| 87 | ;; | ||
| 88 | (autoload (quote a-autoload) "somefile" | ||
| 89 | "Non-interactive autoload." nil nil) | ||
| 90 | |||
| 91 | (autoload (quote a-autoload-interactive) "somefile" | ||
| 92 | "Interactive autoload." t nil) | ||
| 93 | |||
| 94 | |||
| 95 | (defgroup a-defgroup nil | ||
| 96 | "Group for `emacs-lisp' regression-test") | ||
| 97 | |||
| 98 | ;;; Classes | ||
| 99 | ;; | ||
| 100 | (defclass a-class (a-parent) | ||
| 101 | ((slot-1) | ||
| 102 | (slot-2 :initarg :slot-2) | ||
| 103 | (slot-3 :documentation "Doc about slot3") | ||
| 104 | (slot-4 :type 'boolean) | ||
| 105 | ) | ||
| 106 | "Doc String for class.") | ||
| 107 | |||
| 108 | (defclass a-class-abstract () | ||
| 109 | nil | ||
| 110 | "Doc string for abstract class." | ||
| 111 | :abstract t) | ||
| 112 | |||
| 113 | ;;; Structures | ||
| 114 | ;; | ||
| 115 | (defstruct (test-struct-1 :test 'equal) | ||
| 116 | (slot-1 :equal 'eq) | ||
| 117 | slot-2) | ||
| 118 | |||
| 119 | (defstruct test-struct-2 | ||
| 120 | slot-1 | ||
| 121 | slot-2) | ||
| 122 | |||
| 123 | ;;; Semantic specific macros | ||
| 124 | ;; | ||
| 125 | (define-lex a-lexer | ||
| 126 | "Doc String" | ||
| 127 | this | ||
| 128 | that) | ||
| 129 | |||
| 130 | (define-mode-local-override a-overriden-function | ||
| 131 | emacs-lisp-mode (tag) | ||
| 132 | "A function that is overloaded." | ||
| 133 | nil) | ||
| 134 | |||
| 135 | (defvar-mode-local emacs-lisp-mode a-mode-local-def | ||
| 136 | "some value") | ||
| 137 | |||
| 138 | |||
| 139 | ;;; Provide | ||
| 140 | ;; | ||
| 141 | (provide 'test) | ||
diff --git a/test/cedet/tests/test.make b/test/cedet/tests/test.make new file mode 100644 index 00000000000..6f1a4a386ee --- /dev/null +++ b/test/cedet/tests/test.make | |||
| @@ -0,0 +1,60 @@ | |||
| 1 | # Test makefile -*- makefile -*- | ||
| 2 | |||
| 3 | top= | ||
| 4 | ede_FILES=Project.ede Makefile | ||
| 5 | |||
| 6 | example_MISC=semantic-skel.el skeleton.bnf | ||
| 7 | init_LISP=semantic-load.el | ||
| 8 | DISTDIR=$(top)semantic-$(VERSION) | ||
| 9 | |||
| 10 | # really goofy & variables tabs | ||
| 11 | A= B | ||
| 12 | A =B | ||
| 13 | A=B C | ||
| 14 | A=B\ | ||
| 15 | C | ||
| 16 | |||
| 17 | A= http://${B} \ | ||
| 18 | ftp://${B} | ||
| 19 | B= test | ||
| 20 | |||
| 21 | all: example semantic Languages tools senator semantic.info | ||
| 22 | |||
| 23 | test ${B}: foo bar | ||
| 24 | @echo ${A} | ||
| 25 | |||
| 26 | example: | ||
| 27 | @ | ||
| 28 | |||
| 29 | init: $(init_LISP) | ||
| 30 | @echo "(add-to-list 'load-path nil)" > $@-compile-script | ||
| 31 | @if test ! -z "${LOADPATH}" ; then\ | ||
| 32 | for loadpath in ${LOADPATH}; do \ | ||
| 33 | echo "(add-to-list 'load-path \"$$loadpath\")" >> $@-compile-script; \ | ||
| 34 | done;\ | ||
| 35 | fi | ||
| 36 | @echo "(setq debug-on-error t)" >> $@-compile-script | ||
| 37 | $(EMACS) -batch -l $@-compile-script -f batch-byte-compile $^ | ||
| 38 | |||
| 39 | include tesset.mk tusset.mk | ||
| 40 | include oneset.mk | ||
| 41 | |||
| 42 | ifdef SOME_SYMBOL | ||
| 43 | VAR1 = foo | ||
| 44 | else | ||
| 45 | VAR1 = bar | ||
| 46 | endif | ||
| 47 | |||
| 48 | ifndef SOME_OTHER_SYMBOL | ||
| 49 | VAR1 = baz | ||
| 50 | endif | ||
| 51 | |||
| 52 | ifeq ($(VAR1), foo) | ||
| 53 | VAR2 = gleep | ||
| 54 | else | ||
| 55 | ifneq ($(VAR1), foo) | ||
| 56 | VAR2 = glop | ||
| 57 | endif | ||
| 58 | endif | ||
| 59 | |||
| 60 | # End of Makefile | ||
diff --git a/test/cedet/tests/test.py b/test/cedet/tests/test.py new file mode 100644 index 00000000000..1ae5b79e7fb --- /dev/null +++ b/test/cedet/tests/test.py | |||
| @@ -0,0 +1,579 @@ | |||
| 1 | # Test file for Python language. | ||
| 2 | # | ||
| 3 | # $Id: test.py,v 1.1.2.1 2009/09/20 04:00:17 cyd Exp $ | ||
| 4 | |||
| 5 | # Simle class compount statement with blank lines sprinkled. | ||
| 6 | class Foo(Bar): | ||
| 7 | |||
| 8 | x = 1 | ||
| 9 | |||
| 10 | y = 2 | ||
| 11 | |||
| 12 | # Simple def statement with no argument | ||
| 13 | def sss(): | ||
| 14 | i = 1 | ||
| 15 | |||
| 16 | # Simple def statement with arguments | ||
| 17 | def ttt(x,y,z): | ||
| 18 | i = 1 | ||
| 19 | |||
| 20 | import foo | ||
| 21 | |||
| 22 | for x in y: | ||
| 23 | print x | ||
| 24 | |||
| 25 | while y > 0: | ||
| 26 | y = y - 1 | ||
| 27 | |||
| 28 | a=b=c=d=e=f=i=j=k=l=m=n=o=p=q=r=s=t=x=y=1 | ||
| 29 | |||
| 30 | if x: | ||
| 31 | x = 2 | ||
| 32 | y = 3 | ||
| 33 | |||
| 34 | x = 2 | ||
| 35 | y = 3 | ||
| 36 | s and t | ||
| 37 | q | r | ||
| 38 | o ^ p | ||
| 39 | m & n | ||
| 40 | k << l | ||
| 41 | z = 4 | ||
| 42 | i >> j | ||
| 43 | e / f | ||
| 44 | c * d | ||
| 45 | a + b | ||
| 46 | 2 ** 5 | ||
| 47 | x | ||
| 48 | s = "a" "b" "c" | ||
| 49 | 1 | ||
| 50 | |||
| 51 | # implicit continuation lines, see | ||
| 52 | # http://docs.python.org/ref/implicit-joining.html | ||
| 53 | |||
| 54 | a_list = [ 1, 2, 3, | ||
| 55 | 4, 5, | ||
| 56 | 6 ] | ||
| 57 | |||
| 58 | a_tuple = (1, 2, 3, | ||
| 59 | |||
| 60 | 4, 5, 6) | ||
| 61 | |||
| 62 | a_hash = { 'a':1, "b":2, | ||
| 63 | 'c' : 3, | ||
| 64 | "d" : 4 } | ||
| 65 | |||
| 66 | |||
| 67 | def longarglist(a, | ||
| 68 | b, | ||
| 69 | c, | ||
| 70 | d): | ||
| 71 | a=1; | ||
| 72 | b=1; | ||
| 73 | c=1; | ||
| 74 | d=1; | ||
| 75 | |||
| 76 | class longclasslist(xx.yyy, | ||
| 77 | zz.aa): | ||
| 78 | foo=1 | ||
| 79 | |||
| 80 | |||
| 81 | # wisent-python.wy chokes on this! -ryk 6/17/02 | ||
| 82 | |||
| 83 | class HTTPServer(xxx.yyy): | ||
| 84 | allow_reuse_address = 1 # Seems to make sense in testing environment | ||
| 85 | def server_bind(self): | ||
| 86 | SocketServer.TCPServer.server_bind(self) | ||
| 87 | host, port = self.socket.getsockname() | ||
| 88 | self.server_name = socket.getfqdn(host) | ||
| 89 | self.server_port = port | ||
| 90 | |||
| 91 | |||
| 92 | ######################################################################### | ||
| 93 | ### /usr/lib/python2.2/BaseHTTPServer.py | ||
| 94 | ######################################################################### | ||
| 95 | |||
| 96 | """HTTP server base class. | ||
| 97 | |||
| 98 | Note: the class in this module doesn't implement any HTTP request; see | ||
| 99 | SimpleHTTPServer for simple implementations of GET, HEAD and POST | ||
| 100 | (including CGI scripts). | ||
| 101 | |||
| 102 | Contents: | ||
| 103 | |||
| 104 | - BaseHTTPRequestHandler: HTTP request handler base class | ||
| 105 | - test: test function | ||
| 106 | |||
| 107 | XXX To do: | ||
| 108 | |||
| 109 | - send server version | ||
| 110 | - log requests even later (to capture byte count) | ||
| 111 | - log user-agent header and other interesting goodies | ||
| 112 | - send error log to separate file | ||
| 113 | - are request names really case sensitive? | ||
| 114 | |||
| 115 | """ | ||
| 116 | |||
| 117 | |||
| 118 | # See also: | ||
| 119 | # | ||
| 120 | # HTTP Working Group T. Berners-Lee | ||
| 121 | # INTERNET-DRAFT R. T. Fielding | ||
| 122 | # <draft-ietf-http-v10-spec-00.txt> H. Frystyk Nielsen | ||
| 123 | # Expires September 8, 1995 March 8, 1995 | ||
| 124 | # | ||
| 125 | # URL: http://www.ics.uci.edu/pub/ietf/http/draft-ietf-http-v10-spec-00.txt | ||
| 126 | |||
| 127 | |||
| 128 | # Log files | ||
| 129 | # --------- | ||
| 130 | # | ||
| 131 | # Here's a quote from the NCSA httpd docs about log file format. | ||
| 132 | # | ||
| 133 | # | The logfile format is as follows. Each line consists of: | ||
| 134 | # | | ||
| 135 | # | host rfc931 authuser [DD/Mon/YYYY:hh:mm:ss] "request" ddd bbbb | ||
| 136 | # | | ||
| 137 | # | host: Either the DNS name or the IP number of the remote client | ||
| 138 | # | rfc931: Any information returned by identd for this person, | ||
| 139 | # | - otherwise. | ||
| 140 | # | authuser: If user sent a userid for authentication, the user name, | ||
| 141 | # | - otherwise. | ||
| 142 | # | DD: Day | ||
| 143 | # | Mon: Month (calendar name) | ||
| 144 | # | YYYY: Year | ||
| 145 | # | hh: hour (24-hour format, the machine's timezone) | ||
| 146 | # | mm: minutes | ||
| 147 | # | ss: seconds | ||
| 148 | # | request: The first line of the HTTP request as sent by the client. | ||
| 149 | # | ddd: the status code returned by the server, - if not available. | ||
| 150 | # | bbbb: the total number of bytes sent, | ||
| 151 | # | *not including the HTTP/1.0 header*, - if not available | ||
| 152 | # | | ||
| 153 | # | You can determine the name of the file accessed through request. | ||
| 154 | # | ||
| 155 | # (Actually, the latter is only true if you know the server configuration | ||
| 156 | # at the time the request was made!) | ||
| 157 | |||
| 158 | |||
| 159 | __version__ = "0.2" | ||
| 160 | |||
| 161 | __all__ = ["HTTPServer", "BaseHTTPRequestHandler"] | ||
| 162 | |||
| 163 | import sys | ||
| 164 | import time | ||
| 165 | import socket # For gethostbyaddr() | ||
| 166 | import mimetools | ||
| 167 | import SocketServer | ||
| 168 | |||
| 169 | # Default error message | ||
| 170 | DEFAULT_ERROR_MESSAGE = """\ | ||
| 171 | <head> | ||
| 172 | <title>Error response</title> | ||
| 173 | </head> | ||
| 174 | <body> | ||
| 175 | <h1>Error response</h1> | ||
| 176 | <p>Error code %(code)d. | ||
| 177 | <p>Message: %(message)s. | ||
| 178 | <p>Error code explanation: %(code)s = %(explain)s. | ||
| 179 | </body> | ||
| 180 | """ | ||
| 181 | |||
| 182 | |||
| 183 | class HTTPServer(SocketServer.TCPServer): | ||
| 184 | |||
| 185 | allow_reuse_address = 1 # Seems to make sense in testing environment | ||
| 186 | |||
| 187 | def server_bind(self): | ||
| 188 | """Override server_bind to store the server name.""" | ||
| 189 | SocketServer.TCPServer.server_bind(self) | ||
| 190 | host, port = self.socket.getsockname() | ||
| 191 | self.server_name = socket.getfqdn(host) | ||
| 192 | self.server_port = port | ||
| 193 | |||
| 194 | |||
| 195 | class BaseHTTPRequestHandler(SocketServer.StreamRequestHandler): | ||
| 196 | |||
| 197 | """HTTP request handler base class. | ||
| 198 | |||
| 199 | The following explanation of HTTP serves to guide you through the | ||
| 200 | code as well as to expose any misunderstandings I may have about | ||
| 201 | HTTP (so you don't need to read the code to figure out I'm wrong | ||
| 202 | :-). | ||
| 203 | |||
| 204 | HTTP (HyperText Transfer Protocol) is an extensible protocol on | ||
| 205 | top of a reliable stream transport (e.g. TCP/IP). The protocol | ||
| 206 | recognizes three parts to a request: | ||
| 207 | |||
| 208 | 1. One line identifying the request type and path | ||
| 209 | 2. An optional set of RFC-822-style headers | ||
| 210 | 3. An optional data part | ||
| 211 | |||
| 212 | The headers and data are separated by a blank line. | ||
| 213 | |||
| 214 | The first line of the request has the form | ||
| 215 | |||
| 216 | <command> <path> <version> | ||
| 217 | |||
| 218 | where <command> is a (case-sensitive) keyword such as GET or POST, | ||
| 219 | <path> is a string containing path information for the request, | ||
| 220 | and <version> should be the string "HTTP/1.0". <path> is encoded | ||
| 221 | using the URL encoding scheme (using %xx to signify the ASCII | ||
| 222 | character with hex code xx). | ||
| 223 | |||
| 224 | The protocol is vague about whether lines are separated by LF | ||
| 225 | characters or by CRLF pairs -- for compatibility with the widest | ||
| 226 | range of clients, both should be accepted. Similarly, whitespace | ||
| 227 | in the request line should be treated sensibly (allowing multiple | ||
| 228 | spaces between components and allowing trailing whitespace). | ||
| 229 | |||
| 230 | Similarly, for output, lines ought to be separated by CRLF pairs | ||
| 231 | but most clients grok LF characters just fine. | ||
| 232 | |||
| 233 | If the first line of the request has the form | ||
| 234 | |||
| 235 | <command> <path> | ||
| 236 | |||
| 237 | (i.e. <version> is left out) then this is assumed to be an HTTP | ||
| 238 | 0.9 request; this form has no optional headers and data part and | ||
| 239 | the reply consists of just the data. | ||
| 240 | |||
| 241 | The reply form of the HTTP 1.0 protocol again has three parts: | ||
| 242 | |||
| 243 | 1. One line giving the response code | ||
| 244 | 2. An optional set of RFC-822-style headers | ||
| 245 | 3. The data | ||
| 246 | |||
| 247 | Again, the headers and data are separated by a blank line. | ||
| 248 | |||
| 249 | The response code line has the form | ||
| 250 | |||
| 251 | <version> <responsecode> <responsestring> | ||
| 252 | |||
| 253 | where <version> is the protocol version (always "HTTP/1.0"), | ||
| 254 | <responsecode> is a 3-digit response code indicating success or | ||
| 255 | failure of the request, and <responsestring> is an optional | ||
| 256 | human-readable string explaining what the response code means. | ||
| 257 | |||
| 258 | This server parses the request and the headers, and then calls a | ||
| 259 | function specific to the request type (<command>). Specifically, | ||
| 260 | a request SPAM will be handled by a method do_SPAM(). If no | ||
| 261 | such method exists the server sends an error response to the | ||
| 262 | client. If it exists, it is called with no arguments: | ||
| 263 | |||
| 264 | do_SPAM() | ||
| 265 | |||
| 266 | Note that the request name is case sensitive (i.e. SPAM and spam | ||
| 267 | are different requests). | ||
| 268 | |||
| 269 | The various request details are stored in instance variables: | ||
| 270 | |||
| 271 | - client_address is the client IP address in the form (host, | ||
| 272 | port); | ||
| 273 | |||
| 274 | - command, path and version are the broken-down request line; | ||
| 275 | |||
| 276 | - headers is an instance of mimetools.Message (or a derived | ||
| 277 | class) containing the header information; | ||
| 278 | |||
| 279 | - rfile is a file object open for reading positioned at the | ||
| 280 | start of the optional input data part; | ||
| 281 | |||
| 282 | - wfile is a file object open for writing. | ||
| 283 | |||
| 284 | IT IS IMPORTANT TO ADHERE TO THE PROTOCOL FOR WRITING! | ||
| 285 | |||
| 286 | The first thing to be written must be the response line. Then | ||
| 287 | follow 0 or more header lines, then a blank line, and then the | ||
| 288 | actual data (if any). The meaning of the header lines depends on | ||
| 289 | the command executed by the server; in most cases, when data is | ||
| 290 | returned, there should be at least one header line of the form | ||
| 291 | |||
| 292 | Content-type: <type>/<subtype> | ||
| 293 | |||
| 294 | where <type> and <subtype> should be registered MIME types, | ||
| 295 | e.g. "text/html" or "text/plain". | ||
| 296 | |||
| 297 | """ | ||
| 298 | |||
| 299 | # The Python system version, truncated to its first component. | ||
| 300 | sys_version = "Python/" + sys.version.split()[0] | ||
| 301 | |||
| 302 | # The server software version. You may want to override this. | ||
| 303 | # The format is multiple whitespace-separated strings, | ||
| 304 | # where each string is of the form name[/version]. | ||
| 305 | server_version = "BaseHTTP/" + __version__ | ||
| 306 | |||
| 307 | def parse_request(self): | ||
| 308 | """Parse a request (internal). | ||
| 309 | |||
| 310 | The request should be stored in self.raw_request; the results | ||
| 311 | are in self.command, self.path, self.request_version and | ||
| 312 | self.headers. | ||
| 313 | |||
| 314 | Return value is 1 for success, 0 for failure; on failure, an | ||
| 315 | error is sent back. | ||
| 316 | |||
| 317 | """ | ||
| 318 | self.request_version = version = "HTTP/0.9" # Default | ||
| 319 | requestline = self.raw_requestline | ||
| 320 | if requestline[-2:] == '\r\n': | ||
| 321 | requestline = requestline[:-2] | ||
| 322 | elif requestline[-1:] == '\n': | ||
| 323 | requestline = requestline[:-1] | ||
| 324 | self.requestline = requestline | ||
| 325 | words = requestline.split() | ||
| 326 | if len(words) == 3: | ||
| 327 | [command, path, version] = words | ||
| 328 | if version[:5] != 'HTTP/': | ||
| 329 | self.send_error(400, "Bad request version (%s)" % `version`) | ||
| 330 | return 0 | ||
| 331 | elif len(words) == 2: | ||
| 332 | [command, path] = words | ||
| 333 | if command != 'GET': | ||
| 334 | self.send_error(400, | ||
| 335 | "Bad HTTP/0.9 request type (%s)" % `command`) | ||
| 336 | return 0 | ||
| 337 | else: | ||
| 338 | self.send_error(400, "Bad request syntax (%s)" % `requestline`) | ||
| 339 | return 0 | ||
| 340 | self.command, self.path, self.request_version = command, path, version | ||
| 341 | self.headers = self.MessageClass(self.rfile, 0) | ||
| 342 | return 1 | ||
| 343 | |||
| 344 | def handle(self): | ||
| 345 | """Handle a single HTTP request. | ||
| 346 | |||
| 347 | You normally don't need to override this method; see the class | ||
| 348 | __doc__ string for information on how to handle specific HTTP | ||
| 349 | commands such as GET and POST. | ||
| 350 | |||
| 351 | """ | ||
| 352 | |||
| 353 | self.raw_requestline = self.rfile.readline() | ||
| 354 | if not self.parse_request(): # An error code has been sent, just exit | ||
| 355 | return | ||
| 356 | mname = 'do_' + self.command | ||
| 357 | if not hasattr(self, mname): | ||
| 358 | self.send_error(501, "Unsupported method (%s)" % `self.command`) | ||
| 359 | return | ||
| 360 | method = getattr(self, mname) | ||
| 361 | method() | ||
| 362 | |||
| 363 | def send_error(self, code, message=None): | ||
| 364 | """Send and log an error reply. | ||
| 365 | |||
| 366 | Arguments are the error code, and a detailed message. | ||
| 367 | The detailed message defaults to the short entry matching the | ||
| 368 | response code. | ||
| 369 | |||
| 370 | This sends an error response (so it must be called before any | ||
| 371 | output has been generated), logs the error, and finally sends | ||
| 372 | a piece of HTML explaining the error to the user. | ||
| 373 | |||
| 374 | """ | ||
| 375 | |||
| 376 | try: | ||
| 377 | short, long = self.responses[code] | ||
| 378 | except KeyError: | ||
| 379 | short, long = '???', '???' | ||
| 380 | if not message: | ||
| 381 | message = short | ||
| 382 | explain = long | ||
| 383 | self.log_error("code %d, message %s", code, message) | ||
| 384 | self.send_response(code, message) | ||
| 385 | self.send_header("Content-Type", "text/html") | ||
| 386 | self.end_headers() | ||
| 387 | self.wfile.write(self.error_message_format % | ||
| 388 | {'code': code, | ||
| 389 | 'message': message, | ||
| 390 | 'explain': explain}) | ||
| 391 | |||
| 392 | error_message_format = DEFAULT_ERROR_MESSAGE | ||
| 393 | |||
| 394 | def send_response(self, code, message=None): | ||
| 395 | """Send the response header and log the response code. | ||
| 396 | |||
| 397 | Also send two standard headers with the server software | ||
| 398 | version and the current date. | ||
| 399 | |||
| 400 | """ | ||
| 401 | self.log_request(code) | ||
| 402 | if message is None: | ||
| 403 | if self.responses.has_key(code): | ||
| 404 | message = self.responses[code][0] | ||
| 405 | else: | ||
| 406 | message = '' | ||
| 407 | if self.request_version != 'HTTP/0.9': | ||
| 408 | self.wfile.write("%s %s %s\r\n" % | ||
| 409 | (self.protocol_version, str(code), message)) | ||
| 410 | self.send_header('Server', self.version_string()) | ||
| 411 | self.send_header('Date', self.date_time_string()) | ||
| 412 | |||
| 413 | def send_header(self, keyword, value): | ||
| 414 | """Send a MIME header.""" | ||
| 415 | if self.request_version != 'HTTP/0.9': | ||
| 416 | self.wfile.write("%s: %s\r\n" % (keyword, value)) | ||
| 417 | |||
| 418 | def end_headers(self): | ||
| 419 | """Send the blank line ending the MIME headers.""" | ||
| 420 | if self.request_version != 'HTTP/0.9': | ||
| 421 | self.wfile.write("\r\n") | ||
| 422 | |||
| 423 | def log_request(self, code='-', size='-'): | ||
| 424 | """Log an accepted request. | ||
| 425 | |||
| 426 | This is called by send_reponse(). | ||
| 427 | |||
| 428 | """ | ||
| 429 | |||
| 430 | self.log_message('"%s" %s %s', | ||
| 431 | self.requestline, str(code), str(size)) | ||
| 432 | |||
| 433 | def log_error(self, *args): | ||
| 434 | """Log an error. | ||
| 435 | |||
| 436 | This is called when a request cannot be fulfilled. By | ||
| 437 | default it passes the message on to log_message(). | ||
| 438 | |||
| 439 | Arguments are the same as for log_message(). | ||
| 440 | |||
| 441 | XXX This should go to the separate error log. | ||
| 442 | |||
| 443 | """ | ||
| 444 | |||
| 445 | apply(self.log_message, args) | ||
| 446 | |||
| 447 | def log_message(self, format, *args): | ||
| 448 | """Log an arbitrary message. | ||
| 449 | |||
| 450 | This is used by all other logging functions. Override | ||
| 451 | it if you have specific logging wishes. | ||
| 452 | |||
| 453 | The first argument, FORMAT, is a format string for the | ||
| 454 | message to be logged. If the format string contains | ||
| 455 | any % escapes requiring parameters, they should be | ||
| 456 | specified as subsequent arguments (it's just like | ||
| 457 | printf!). | ||
| 458 | |||
| 459 | The client host and current date/time are prefixed to | ||
| 460 | every message. | ||
| 461 | |||
| 462 | """ | ||
| 463 | |||
| 464 | sys.stderr.write("%s - - [%s] %s\n" % | ||
| 465 | (self.address_string(), | ||
| 466 | self.log_date_time_string(), | ||
| 467 | format%args)) | ||
| 468 | |||
| 469 | def version_string(self): | ||
| 470 | """Return the server software version string.""" | ||
| 471 | return self.server_version + ' ' + self.sys_version | ||
| 472 | |||
| 473 | def date_time_string(self): | ||
| 474 | """Return the current date and time formatted for a message header.""" | ||
| 475 | now = time.time() | ||
| 476 | year, month, day, hh, mm, ss, wd, y, z = time.gmtime(now) | ||
| 477 | s = "%s, %02d %3s %4d %02d:%02d:%02d GMT" % ( | ||
| 478 | self.weekdayname[wd], | ||
| 479 | day, self.monthname[month], year, | ||
| 480 | hh, mm, ss) | ||
| 481 | return s | ||
| 482 | |||
| 483 | def log_date_time_string(self): | ||
| 484 | """Return the current time formatted for logging.""" | ||
| 485 | now = time.time() | ||
| 486 | year, month, day, hh, mm, ss, x, y, z = time.localtime(now) | ||
| 487 | s = "%02d/%3s/%04d %02d:%02d:%02d" % ( | ||
| 488 | day, self.monthname[month], year, hh, mm, ss) | ||
| 489 | return s | ||
| 490 | |||
| 491 | weekdayname = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] | ||
| 492 | |||
| 493 | monthname = [None, | ||
| 494 | 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', | ||
| 495 | 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] | ||
| 496 | |||
| 497 | def address_string(self): | ||
| 498 | """Return the client address formatted for logging. | ||
| 499 | |||
| 500 | This version looks up the full hostname using gethostbyaddr(), | ||
| 501 | and tries to find a name that contains at least one dot. | ||
| 502 | |||
| 503 | """ | ||
| 504 | |||
| 505 | host, port = self.client_address | ||
| 506 | return socket.getfqdn(host) | ||
| 507 | |||
| 508 | # Essentially static class variables | ||
| 509 | |||
| 510 | # The version of the HTTP protocol we support. | ||
| 511 | # Don't override unless you know what you're doing (hint: incoming | ||
| 512 | # requests are required to have exactly this version string). | ||
| 513 | protocol_version = "HTTP/1.0" | ||
| 514 | |||
| 515 | # The Message-like class used to parse headers | ||
| 516 | MessageClass = mimetools.Message | ||
| 517 | |||
| 518 | # Table mapping response codes to messages; entries have the | ||
| 519 | # form {code: (shortmessage, longmessage)}. | ||
| 520 | # See http://www.w3.org/hypertext/WWW/Protocols/HTTP/HTRESP.html | ||
| 521 | responses = { | ||
| 522 | 200: ('OK', 'Request fulfilled, document follows'), | ||
| 523 | 201: ('Created', 'Document created, URL follows'), | ||
| 524 | 202: ('Accepted', | ||
| 525 | 'Request accepted, processing continues off-line'), | ||
| 526 | 203: ('Partial information', 'Request fulfilled from cache'), | ||
| 527 | 204: ('No response', 'Request fulfilled, nothing follows'), | ||
| 528 | |||
| 529 | 301: ('Moved', 'Object moved permanently -- see URI list'), | ||
| 530 | 302: ('Found', 'Object moved temporarily -- see URI list'), | ||
| 531 | 303: ('Method', 'Object moved -- see Method and URL list'), | ||
| 532 | 304: ('Not modified', | ||
| 533 | 'Document has not changed singe given time'), | ||
| 534 | |||
| 535 | 400: ('Bad request', | ||
| 536 | 'Bad request syntax or unsupported method'), | ||
| 537 | 401: ('Unauthorized', | ||
| 538 | 'No permission -- see authorization schemes'), | ||
| 539 | 402: ('Payment required', | ||
| 540 | 'No payment -- see charging schemes'), | ||
| 541 | 403: ('Forbidden', | ||
| 542 | 'Request forbidden -- authorization will not help'), | ||
| 543 | 404: ('Not found', 'Nothing matches the given URI'), | ||
| 544 | |||
| 545 | 500: ('Internal error', 'Server got itself in trouble'), | ||
| 546 | 501: ('Not implemented', | ||
| 547 | 'Server does not support this operation'), | ||
| 548 | 502: ('Service temporarily overloaded', | ||
| 549 | 'The server cannot process the request due to a high load'), | ||
| 550 | 503: ('Gateway timeout', | ||
| 551 | 'The gateway server did not receive a timely response'), | ||
| 552 | |||
| 553 | } | ||
| 554 | |||
| 555 | |||
| 556 | def test(HandlerClass = BaseHTTPRequestHandler, | ||
| 557 | ServerClass = HTTPServer): | ||
| 558 | """Test the HTTP request handler class. | ||
| 559 | |||
| 560 | This runs an HTTP server on port 8000 (or the first command line | ||
| 561 | argument). | ||
| 562 | |||
| 563 | """ | ||
| 564 | |||
| 565 | if sys.argv[1:]: | ||
| 566 | port = int(sys.argv[1]) | ||
| 567 | else: | ||
| 568 | port = 8000 | ||
| 569 | server_address = ('', port) | ||
| 570 | |||
| 571 | httpd = ServerClass(server_address, HandlerClass) | ||
| 572 | |||
| 573 | sa = httpd.socket.getsockname() | ||
| 574 | print "Serving HTTP on", sa[0], "port", sa[1], "..." | ||
| 575 | httpd.serve_forever() | ||
| 576 | |||
| 577 | |||
| 578 | if __name__ == '__main__': | ||
| 579 | test() | ||
diff --git a/test/cedet/tests/testdoublens.cpp b/test/cedet/tests/testdoublens.cpp new file mode 100644 index 00000000000..1cf48761ac7 --- /dev/null +++ b/test/cedet/tests/testdoublens.cpp | |||
| @@ -0,0 +1,148 @@ | |||
| 1 | // | ||
| 2 | // CPP file for semantic-ia-utest | ||
| 3 | // completion engine unit tests. | ||
| 4 | // | ||
| 5 | #include "testdoublens.hpp" | ||
| 6 | |||
| 7 | namespace Name1 { | ||
| 8 | namespace Name2 { | ||
| 9 | |||
| 10 | Foo::Foo() | ||
| 11 | { | ||
| 12 | p// -1- | ||
| 13 | // #1# ( "pMumble" "publishStuff" ) | ||
| 14 | ; | ||
| 15 | } | ||
| 16 | |||
| 17 | int Foo::get() // ^1^ | ||
| 18 | { | ||
| 19 | p// -2- | ||
| 20 | // #2# ( "pMumble" "publishStuff" ) | ||
| 21 | ; | ||
| 22 | return 0; | ||
| 23 | } | ||
| 24 | |||
| 25 | void Foo::publishStuff(int /* a */, int /* b */) // ^2^ | ||
| 26 | { | ||
| 27 | } | ||
| 28 | |||
| 29 | void Foo::sendStuff(int /* a */, int /* b */) // ^3^ | ||
| 30 | { | ||
| 31 | } | ||
| 32 | |||
| 33 | } // namespace Name2 | ||
| 34 | } // namespace Name1 | ||
| 35 | |||
| 36 | // Test multiple levels of metatype expansion | ||
| 37 | int test_fcn () { | ||
| 38 | stage3_Foo MyFoo; | ||
| 39 | |||
| 40 | MyFoo.// -3- | ||
| 41 | // #3# ( "Mumble" "get" ) | ||
| 42 | ; | ||
| 43 | |||
| 44 | Name1::Name2::F//-4- | ||
| 45 | // #4# ( "Foo" ) | ||
| 46 | ; | ||
| 47 | |||
| 48 | // @TODO - get this working... | ||
| 49 | Name1::stage2_Foo::M//-5- | ||
| 50 | /// #5# ( "Mumble" ) | ||
| 51 | ; | ||
| 52 | } | ||
| 53 | |||
| 54 | stage3_Foo foo_fcn() { | ||
| 55 | // Can we go "up" to foo with senator-go-to-up-reference? | ||
| 56 | } | ||
| 57 | |||
| 58 | |||
| 59 | // Second test from Ravikiran Rajagopal | ||
| 60 | |||
| 61 | namespace A { | ||
| 62 | class foo { | ||
| 63 | public: | ||
| 64 | void aa(); | ||
| 65 | void bb(); | ||
| 66 | }; | ||
| 67 | } | ||
| 68 | namespace A { | ||
| 69 | class bar { | ||
| 70 | public: | ||
| 71 | void xx(); | ||
| 72 | public: | ||
| 73 | foo myFoo; | ||
| 74 | }; | ||
| 75 | |||
| 76 | void bar::xx() | ||
| 77 | { | ||
| 78 | myFoo.// -6- <--- cursor is here after the dot | ||
| 79 | // #6# ( "aa" "bb" ) | ||
| 80 | ; | ||
| 81 | } | ||
| 82 | } | ||
| 83 | |||
| 84 | // Double namespace example from Hannu Koivisto | ||
| 85 | // | ||
| 86 | // This is tricky because the parent class "Foo" is found within the | ||
| 87 | // scope of B, so the scope calculation needs to put that together | ||
| 88 | // before searching for parents in scope. | ||
| 89 | namespace a { | ||
| 90 | namespace b { | ||
| 91 | |||
| 92 | class Bar : public Foo | ||
| 93 | { | ||
| 94 | int baz(); | ||
| 95 | }; | ||
| 96 | |||
| 97 | int Bar::baz() | ||
| 98 | { | ||
| 99 | return dum// -7- | ||
| 100 | // #7# ( "dumdum" ) | ||
| 101 | ; | ||
| 102 | } | ||
| 103 | |||
| 104 | } // namespace b | ||
| 105 | } // namespace a | ||
| 106 | |||
| 107 | // Three namespace example from Hannu Koivisto | ||
| 108 | // | ||
| 109 | // This one is special in that the name e::Foo, where "e" is in | ||
| 110 | // the scope, and not referenced from the global namespace. This | ||
| 111 | // wasn't previously handled, so the fullscope needed to be added | ||
| 112 | // to the list of things searched when in split-name decent search mode | ||
| 113 | // for scopes. | ||
| 114 | |||
| 115 | namespace d { | ||
| 116 | namespace e { | ||
| 117 | |||
| 118 | class Foo | ||
| 119 | { | ||
| 120 | public: | ||
| 121 | int write(); | ||
| 122 | }; | ||
| 123 | |||
| 124 | } // namespace d | ||
| 125 | } // namespace e | ||
| 126 | |||
| 127 | |||
| 128 | namespace d { | ||
| 129 | namespace f { | ||
| 130 | |||
| 131 | class Bar | ||
| 132 | { | ||
| 133 | public: | ||
| 134 | int baz(); | ||
| 135 | |||
| 136 | private: | ||
| 137 | e::Foo &foo; | ||
| 138 | }; | ||
| 139 | |||
| 140 | int Bar::baz() | ||
| 141 | { | ||
| 142 | return foo.w// -8- | ||
| 143 | // #8# ( "write" ) | ||
| 144 | ; | ||
| 145 | } | ||
| 146 | |||
| 147 | } // namespace f | ||
| 148 | } // namespace d | ||
diff --git a/test/cedet/tests/testdoublens.hpp b/test/cedet/tests/testdoublens.hpp new file mode 100644 index 00000000000..3f9a8a251c3 --- /dev/null +++ b/test/cedet/tests/testdoublens.hpp | |||
| @@ -0,0 +1,51 @@ | |||
| 1 | // | ||
| 2 | // Header file used in one of the ia-utest tests. | ||
| 3 | // | ||
| 4 | namespace Name1 { | ||
| 5 | namespace Name2 { | ||
| 6 | |||
| 7 | class Foo | ||
| 8 | { | ||
| 9 | typedef unsigned int Mumble; | ||
| 10 | public: | ||
| 11 | Foo(); | ||
| 12 | ~Foo(); | ||
| 13 | int get(); | ||
| 14 | |||
| 15 | private: | ||
| 16 | void publishStuff(int a, int b); | ||
| 17 | |||
| 18 | void sendStuff(int a, int b); | ||
| 19 | |||
| 20 | Mumble* pMumble; | ||
| 21 | }; | ||
| 22 | |||
| 23 | typedef Foo stage1_Foo; | ||
| 24 | |||
| 25 | } // namespace Name2 | ||
| 26 | |||
| 27 | typedef Name2::stage1_Foo stage2_Foo; | ||
| 28 | |||
| 29 | typedef Name2::Foo decl_stage1_Foo; | ||
| 30 | |||
| 31 | } // namespace Name1 | ||
| 32 | |||
| 33 | typedef Name1::stage2_Foo stage3_Foo; | ||
| 34 | |||
| 35 | |||
| 36 | // Double namespace from Hannu Koivisto | ||
| 37 | namespace a { | ||
| 38 | namespace b { | ||
| 39 | |||
| 40 | class Foo | ||
| 41 | { | ||
| 42 | struct Dum { | ||
| 43 | int diDum; | ||
| 44 | }; | ||
| 45 | |||
| 46 | protected: | ||
| 47 | mutable a::b::Foo::Dum dumdum; | ||
| 48 | }; | ||
| 49 | |||
| 50 | } // namespace b | ||
| 51 | } // namespace a | ||
diff --git a/test/cedet/tests/testfriends.cpp b/test/cedet/tests/testfriends.cpp new file mode 100644 index 00000000000..f84ed5a2190 --- /dev/null +++ b/test/cedet/tests/testfriends.cpp | |||
| @@ -0,0 +1,37 @@ | |||
| 1 | // Test parsing of friends and how they are used in completion. | ||
| 2 | /* | ||
| 3 | >> Thanks Damien Profeta for the nice example. | ||
| 4 | > | ||
| 5 | > I paste a small example. | ||
| 6 | > It would be great if friend can be well parsed and even greater if | ||
| 7 | > class B can access to all the members of A. | ||
| 8 | */ | ||
| 9 | |||
| 10 | class Af // %2% ( ( "testfriends.cpp" ) ( "Af" "B::testB" ) ) | ||
| 11 | { | ||
| 12 | public: | ||
| 13 | int pubVar; | ||
| 14 | private: | ||
| 15 | int privateVar; | ||
| 16 | |||
| 17 | friend class B; | ||
| 18 | |||
| 19 | }; | ||
| 20 | |||
| 21 | class B | ||
| 22 | { | ||
| 23 | public: | ||
| 24 | int testB(); | ||
| 25 | int testAB(); | ||
| 26 | |||
| 27 | }; | ||
| 28 | |||
| 29 | |||
| 30 | int B::testB() { | ||
| 31 | Af classA; | ||
| 32 | classA.//-1- | ||
| 33 | ; //#1# ( "privateVar" "pubVar" ) | ||
| 34 | } | ||
| 35 | |||
| 36 | int B::testAB() { // %1% ( ( "testfriends.cpp" ) ( "B" "B::testAB" ) ) | ||
| 37 | } | ||
diff --git a/test/cedet/tests/testjavacomp.java b/test/cedet/tests/testjavacomp.java new file mode 100644 index 00000000000..0c2604f5bf1 --- /dev/null +++ b/test/cedet/tests/testjavacomp.java | |||
| @@ -0,0 +1,69 @@ | |||
| 1 | /** testjavacomp.java --- | ||
| 2 | * | ||
| 3 | * Copyright (C) 2009 Eric M. Ludlam | ||
| 4 | * | ||
| 5 | * Author: Eric M. Ludlam <eric@siege-engine.com> | ||
| 6 | * X-RCS: $Id: testjavacomp.java,v 1.1.2.1 2009/09/20 04:00:18 cyd Exp $ | ||
| 7 | * | ||
| 8 | * This program is free software; you can redistribute it and/or | ||
| 9 | * modify it under the terms of the GNU General Public License as | ||
| 10 | * published by the Free Software Foundation; either version 2, or (at | ||
| 11 | * your option) any later version. | ||
| 12 | * | ||
| 13 | * This program is distributed in the hope that it will be useful, but | ||
| 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 16 | * General Public License for more details. | ||
| 17 | * | ||
| 18 | * You should have received a copy of the GNU General Public License | ||
| 19 | * along with this program; see the file COPYING. If not, write to | ||
| 20 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
| 21 | * Boston, MA 02110-1301, USA. | ||
| 22 | */ | ||
| 23 | |||
| 24 | package tests.testjavacomp; | ||
| 25 | |||
| 26 | class secondClass { | ||
| 27 | private void scFuncOne() { } | ||
| 28 | public void scFuncOne() { } | ||
| 29 | } | ||
| 30 | |||
| 31 | |||
| 32 | public class testjavacomp { | ||
| 33 | |||
| 34 | private int funcOne() { } | ||
| 35 | private int funcTwo() { } | ||
| 36 | private char funcThree() { } | ||
| 37 | |||
| 38 | class nestedClass { | ||
| 39 | private void ncFuncOne() { } | ||
| 40 | public void ncFuncOne() { } | ||
| 41 | } | ||
| 42 | |||
| 43 | public void publicFunc() { | ||
| 44 | |||
| 45 | int i; | ||
| 46 | |||
| 47 | i = fu// -1- | ||
| 48 | // #1# ( "funcOne" "funcTwo" ) | ||
| 49 | ; | ||
| 50 | |||
| 51 | fu// -2- | ||
| 52 | // #2# ( "funcOne" "funcThree" "funcTwo" ) | ||
| 53 | ; | ||
| 54 | |||
| 55 | secondClass SC; | ||
| 56 | |||
| 57 | SC.//-3- | ||
| 58 | // #3# ( "scFuncOne" ) | ||
| 59 | ; | ||
| 60 | |||
| 61 | nestedClass NC; | ||
| 62 | |||
| 63 | // @todo - need to fix this? I don't know if this is legal java. | ||
| 64 | NC.// - 4- | ||
| 65 | // #4# ( "ncFuncOne" ) | ||
| 66 | ; | ||
| 67 | } | ||
| 68 | |||
| 69 | } // testjavacomp | ||
diff --git a/test/cedet/tests/testnsp.cpp b/test/cedet/tests/testnsp.cpp new file mode 100644 index 00000000000..00723c693cd --- /dev/null +++ b/test/cedet/tests/testnsp.cpp | |||
| @@ -0,0 +1,28 @@ | |||
| 1 | // Test NSP (Name space parent) | ||
| 2 | // | ||
| 3 | // Test dereferencing parents based on local parent scope. | ||
| 4 | // | ||
| 5 | // Derived from data David Engster provided. | ||
| 6 | |||
| 7 | namespace nsp { | ||
| 8 | |||
| 9 | class rootclass { | ||
| 10 | public: | ||
| 11 | int fromroot() {}; | ||
| 12 | }; | ||
| 13 | |||
| 14 | } | ||
| 15 | |||
| 16 | namespace nsp { | ||
| 17 | class childclass : public rootclass { | ||
| 18 | public: | ||
| 19 | int fromchild() {}; | ||
| 20 | }; | ||
| 21 | } | ||
| 22 | |||
| 23 | void myfcn_not_in_ns (void) { | ||
| 24 | nsp::childclass test; | ||
| 25 | |||
| 26 | test.// -1- | ||
| 27 | ; // #1# ( "fromchild" "fromroot" ) | ||
| 28 | } | ||
diff --git a/test/cedet/tests/testpolymorph.cpp b/test/cedet/tests/testpolymorph.cpp new file mode 100644 index 00000000000..fea842d6902 --- /dev/null +++ b/test/cedet/tests/testpolymorph.cpp | |||
| @@ -0,0 +1,131 @@ | |||
| 1 | /** testpolymorph.cpp --- A sequence of polymorphism examples. | ||
| 2 | * | ||
| 3 | * Copyright (C) 2009 Eric M. Ludlam | ||
| 4 | * | ||
| 5 | * Author: Eric M. Ludlam <eric@siege-engine.com> | ||
| 6 | * X-RCS: $Id: testpolymorph.cpp,v 1.1.2.1 2009/09/20 04:00:18 cyd Exp $ | ||
| 7 | * | ||
| 8 | * This program is free software; you can redistribute it and/or | ||
| 9 | * modify it under the terms of the GNU General Public License as | ||
| 10 | * published by the Free Software Foundation; either version 2, or (at | ||
| 11 | * your option) any later version. | ||
| 12 | * | ||
| 13 | * This program is distributed in the hope that it will be useful, but | ||
| 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 16 | * General Public License for more details. | ||
| 17 | * | ||
| 18 | * You should have received a copy of the GNU General Public License | ||
| 19 | * along with this program; see the file COPYING. If not, write to | ||
| 20 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
| 21 | * Boston, MA 02110-1301, USA. | ||
| 22 | */ | ||
| 23 | |||
| 24 | #include <cmath> | ||
| 25 | |||
| 26 | // Test 1 - Functions w/ prototypes | ||
| 27 | namespace proto { | ||
| 28 | |||
| 29 | int pt_func1(int arg1); | ||
| 30 | int pt_func1(int arg1) { | ||
| 31 | return 0; | ||
| 32 | } | ||
| 33 | |||
| 34 | } | ||
| 35 | |||
| 36 | // Test 2 - Functions w/ different arg lists. | ||
| 37 | namespace fcn_poly { | ||
| 38 | |||
| 39 | int pm_func(void) { | ||
| 40 | return 0; | ||
| 41 | } | ||
| 42 | int pm_func(int a) { | ||
| 43 | return a; | ||
| 44 | } | ||
| 45 | int pm_func(char a) { | ||
| 46 | return int(a); | ||
| 47 | } | ||
| 48 | int pm_func(double a) { | ||
| 49 | return int(floor(a)); | ||
| 50 | } | ||
| 51 | |||
| 52 | } | ||
| 53 | |||
| 54 | // Test 3 - Methods w/ differet arg lists. | ||
| 55 | class meth_poly { | ||
| 56 | public: | ||
| 57 | int pm_meth(void) { | ||
| 58 | return 0; | ||
| 59 | } | ||
| 60 | int pm_meth(int a) { | ||
| 61 | return a; | ||
| 62 | } | ||
| 63 | int pm_meth(char a) { | ||
| 64 | return int(a); | ||
| 65 | } | ||
| 66 | int pm_meth(double a) { | ||
| 67 | return int(floor(a)); | ||
| 68 | } | ||
| 69 | |||
| 70 | }; | ||
| 71 | |||
| 72 | // Test 4 - Templates w/ partial specifiers. | ||
| 73 | namespace template_partial_spec { | ||
| 74 | template <typename T> class test | ||
| 75 | { | ||
| 76 | public: | ||
| 77 | void doSomething(T t) { }; | ||
| 78 | }; | ||
| 79 | |||
| 80 | template <typename T> class test<T *> | ||
| 81 | { | ||
| 82 | public: | ||
| 83 | void doSomething(T* t) { }; | ||
| 84 | }; | ||
| 85 | } | ||
| 86 | |||
| 87 | // Test 5 - Templates w/ full specicialization which may or may not share | ||
| 88 | // common functions. | ||
| 89 | namespace template_full_spec { | ||
| 90 | template <typename T> class test | ||
| 91 | { | ||
| 92 | public: | ||
| 93 | void doSomething(T t) { }; | ||
| 94 | void doSomethingElse(T t) { }; | ||
| 95 | }; | ||
| 96 | |||
| 97 | template <> class test<int> | ||
| 98 | { | ||
| 99 | public: | ||
| 100 | void doSomethingElse(int t) { }; | ||
| 101 | void doSomethingCompletelyDifferent(int t) { }; | ||
| 102 | }; | ||
| 103 | } | ||
| 104 | |||
| 105 | // Test 6 - Dto., but for templates with multiple parameters. | ||
| 106 | namespace template_multiple_spec { | ||
| 107 | template <typename T1, typename T2> class test | ||
| 108 | { | ||
| 109 | public: | ||
| 110 | void doSomething(T1 t) { }; | ||
| 111 | void doSomethingElse(T2 t) { }; | ||
| 112 | }; | ||
| 113 | |||
| 114 | template <typename T2> class test<int, T2> | ||
| 115 | { | ||
| 116 | public: | ||
| 117 | void doSomething(int t) { }; | ||
| 118 | void doSomethingElse(T2 t) { }; | ||
| 119 | }; | ||
| 120 | |||
| 121 | template <> class test<float, int> | ||
| 122 | { | ||
| 123 | public: | ||
| 124 | void doSomething(float t) { }; | ||
| 125 | void doSomethingElse(int t) { }; | ||
| 126 | void doNothing(void) { }; | ||
| 127 | }; | ||
| 128 | } | ||
| 129 | |||
| 130 | |||
| 131 | // End of polymorphism test file. | ||
diff --git a/test/cedet/tests/testspp.c b/test/cedet/tests/testspp.c new file mode 100644 index 00000000000..c7ff76203b2 --- /dev/null +++ b/test/cedet/tests/testspp.c | |||
| @@ -0,0 +1,84 @@ | |||
| 1 | /* Attempt to test the C preprocessor | ||
| 2 | * | ||
| 3 | */ | ||
| 4 | |||
| 5 | int some_fcn (){} | ||
| 6 | |||
| 7 | |||
| 8 | #ifndef MOOSE | ||
| 9 | int pre_show_moose(){} | ||
| 10 | #endif | ||
| 11 | |||
| 12 | #ifdef MOOSE | ||
| 13 | int pre_dont_show_moose(){} | ||
| 14 | #endif | ||
| 15 | |||
| 16 | #if !defined(MOOSE) | ||
| 17 | int pre_show_moose_if(){} | ||
| 18 | #endif | ||
| 19 | |||
| 20 | #if defined(MOOSE) | ||
| 21 | int pre_dont_show_moose_if(){} | ||
| 22 | #endif | ||
| 23 | |||
| 24 | #define MOOSE | ||
| 25 | |||
| 26 | #if 0 | ||
| 27 | int dont_show_function_if_0(){} | ||
| 28 | #endif | ||
| 29 | |||
| 30 | #if 1 | ||
| 31 | int show_function_if_1(){} | ||
| 32 | #endif | ||
| 33 | |||
| 34 | #ifdef MOOSE | ||
| 35 | int moose_function(){} | ||
| 36 | #endif | ||
| 37 | |||
| 38 | #ifndef MOOSE | ||
| 39 | int dont_show_moose(){} | ||
| 40 | #endif | ||
| 41 | |||
| 42 | #if defined(MOOSE) | ||
| 43 | int moose_function_if(){} | ||
| 44 | #endif | ||
| 45 | |||
| 46 | #if !defined(MOOSE) | ||
| 47 | int dont_show_moose_if() {} | ||
| 48 | #endif | ||
| 49 | |||
| 50 | #undef MOOSE | ||
| 51 | |||
| 52 | #ifdef MOOSE | ||
| 53 | int no_handy_moose(){} | ||
| 54 | #endif | ||
| 55 | |||
| 56 | #ifndef MOOSE | ||
| 57 | int show_moose_else() {} | ||
| 58 | #else | ||
| 59 | int no_show_moose_else(){} | ||
| 60 | #endif | ||
| 61 | |||
| 62 | |||
| 63 | #ifdef MOOSE | ||
| 64 | int no_show_moose_else_2() {} | ||
| 65 | #else | ||
| 66 | int show_moose_else_2() {} | ||
| 67 | #endif | ||
| 68 | |||
| 69 | #if defined(MOOSE) | ||
| 70 | int no_show_moose_elif() {} | ||
| 71 | #elif !defined(MOOSE) | ||
| 72 | int show_moose_elif() {} | ||
| 73 | #else | ||
| 74 | int no_show_moose_elif_else() {} | ||
| 75 | #endif | ||
| 76 | |||
| 77 | #if defined(MOOSE) | ||
| 78 | int no_show_moose_if_elif_2() {} | ||
| 79 | #elif defined(COW) | ||
| 80 | int no_show_moose_elif_2() {} | ||
| 81 | #else | ||
| 82 | int show_moose_elif_else() {} | ||
| 83 | #endif | ||
| 84 | |||
diff --git a/test/cedet/tests/testsppcomplete.c b/test/cedet/tests/testsppcomplete.c new file mode 100644 index 00000000000..4a37e885f22 --- /dev/null +++ b/test/cedet/tests/testsppcomplete.c | |||
| @@ -0,0 +1,29 @@ | |||
| 1 | /* Example provided by Hannes Janetzek */ | ||
| 2 | |||
| 3 | struct Test { int test; }; | ||
| 4 | |||
| 5 | #define BLA(_type) \ | ||
| 6 | _type *bla = (_type*) malloc(sizeof(_type)); | ||
| 7 | |||
| 8 | #define BLUB(_type) \ | ||
| 9 | (_type*)malloc(sizeof(_type)); | ||
| 10 | |||
| 11 | #define FOO(_type) \ | ||
| 12 | _type *foo = BLUB(_type); | ||
| 13 | |||
| 14 | #define BAR(_type) \ | ||
| 15 | _type *bar = (*_type)BLUB(_type); | ||
| 16 | |||
| 17 | int main(int argc, char *argv[]) { | ||
| 18 | BLA(Test); | ||
| 19 | bla->// -1- | ||
| 20 | ; // #1# ( "test" ) | ||
| 21 | |||
| 22 | FOO(Test); | ||
| 23 | foo->// -2- | ||
| 24 | ; // #2# ( "test" ) | ||
| 25 | |||
| 26 | BAR(Test); | ||
| 27 | bar->// -3- | ||
| 28 | ; // #3# ( "test" ) | ||
| 29 | } | ||
diff --git a/test/cedet/tests/testsppreplace.c b/test/cedet/tests/testsppreplace.c new file mode 100644 index 00000000000..390e0953fcb --- /dev/null +++ b/test/cedet/tests/testsppreplace.c | |||
| @@ -0,0 +1,135 @@ | |||
| 1 | /* Test CPP/SPP Replacement | ||
| 2 | */ | ||
| 3 | |||
| 4 | /* TEST: The EMU keyword doesn't screw up the function defn. */ | ||
| 5 | #define EMU | ||
| 6 | #define EMU2 /*comment*/ | ||
| 7 | char EMU parse_around_emu EMU2 (EMU) | ||
| 8 | { | ||
| 9 | } | ||
| 10 | |||
| 11 | /* TEST: A simple word can be replaced in a definition. */ | ||
| 12 | #define SUBFLOAT /* Some Float */ float | ||
| 13 | SUBFLOAT returnanfloat() | ||
| 14 | { | ||
| 15 | } | ||
| 16 | |||
| 17 | /* TEST: Punctuation an be replaced in a definition. */ | ||
| 18 | #define COLON : | ||
| 19 | int foo COLON COLON bar () | ||
| 20 | { | ||
| 21 | } | ||
| 22 | |||
| 23 | /* TEST: Multiple lexical characters in a definition */ | ||
| 24 | #define SUPER mysuper:: | ||
| 25 | int SUPER baz () | ||
| 26 | { | ||
| 27 | } | ||
| 28 | |||
| 29 | /* TEST: Macro replacement. */ | ||
| 30 | #define INT_FCN(name) int name (int in) | ||
| 31 | |||
| 32 | INT_FCN(increment) { | ||
| 33 | return in+1; | ||
| 34 | } | ||
| 35 | |||
| 36 | /* TEST: Macro replacement with complex args */ | ||
| 37 | #define P_(proto) () | ||
| 38 | |||
| 39 | int myFcn1 P_((a,b)); | ||
| 40 | |||
| 41 | #define P__(proto) proto | ||
| 42 | |||
| 43 | int myFcn2 P__((int a, int b)); | ||
| 44 | int myFcn3 (int a, int b); | ||
| 45 | |||
| 46 | /* TEST: Multiple args to a macro. */ | ||
| 47 | #define MULTI_ARGS(name, field1, field2, field3) struct name { int field1; int field2; int field3; } | ||
| 48 | |||
| 49 | MULTI_ARGS(ma_struct, moose, penguin, emu); | ||
| 50 | |||
| 51 | /* TEST: Macro w/ args, but no body. */ | ||
| 52 | #define NO_BODY(name) | ||
| 53 | |||
| 54 | NO_BODY(Moose); | ||
| 55 | |||
| 56 | /* TEST: Not a macro with args, but close. */ | ||
| 57 | #define NOT_WITH_ARGS (moose) | ||
| 58 | |||
| 59 | int not_with_args_fcn NOT_WITH_ARGS | ||
| 60 | { | ||
| 61 | } | ||
| 62 | |||
| 63 | /* TEST: macro w/ continuation. */ | ||
| 64 | #define WITH_CONT \ | ||
| 65 | continuation_symbol | ||
| 66 | |||
| 67 | int WITH_CONT () { }; | ||
| 68 | |||
| 69 | /* TEST: macros in a macro - tail processing */ | ||
| 70 | #define tail_with_args_and_long_name(a) (int a) | ||
| 71 | #define int_arg tail_with_args_and_long_name | ||
| 72 | |||
| 73 | int tail int_arg(q) {} | ||
| 74 | |||
| 75 | /* TEST: macros used improperly. */ | ||
| 76 | #define tail_fail tail_with_args_and_long_name(q) | ||
| 77 | |||
| 78 | int tail_fcn tail_fail(q); | ||
| 79 | |||
| 80 | /* TEST: feature of CPP from LSD <lsdsgster@...> */ | ||
| 81 | #define __gthrw_(name) __gthrw_ ## name | ||
| 82 | |||
| 83 | int __gthrw_(foo) (int arg1) { } | ||
| 84 | |||
| 85 | /* TEST: macros using macros */ | ||
| 86 | #define macro_foo foo | ||
| 87 | #define mf_declare int macro_foo | ||
| 88 | |||
| 89 | mf_declare; | ||
| 90 | |||
| 91 | /* TEST: macros with args using macros */ | ||
| 92 | #define Amacro(A) (int A) | ||
| 93 | #define mf_Amacro(B) int B Amacro(B) | ||
| 94 | |||
| 95 | mf_Amacro(noodle); | ||
| 96 | |||
| 97 | /* TEST: Double macro using the argument stack. */ | ||
| 98 | #define MACRO0(name) int that_ ## name(int i); | ||
| 99 | #define MACRO1(name) int this_ ## name(int i); | ||
| 100 | #define MACRO2(name) MACRO0(name) MACRO1(name) | ||
| 101 | |||
| 102 | MACRO2(foo) | ||
| 103 | |||
| 104 | /* TEST: The G++ namespace macro hack. Not really part of SPP. */ | ||
| 105 | _GLIBCXX_BEGIN_NAMESPACE(baz) | ||
| 106 | |||
| 107 | int bazfnc(int b) { } | ||
| 108 | |||
| 109 | _GLIBCXX_END_NAMESPACE; | ||
| 110 | |||
| 111 | _GLIBCXX_BEGIN_NESTED_NAMESPACE(foo,bar) | ||
| 112 | |||
| 113 | int foo_bar_func(int a) { } | ||
| 114 | |||
| 115 | _GLIBCXX_END_NESTED_NAMESPACE; | ||
| 116 | |||
| 117 | |||
| 118 | /* TEST: The VC++ macro hack. */ | ||
| 119 | _STD_BEGIN | ||
| 120 | |||
| 121 | int inside_std_namespace(int a) { } | ||
| 122 | |||
| 123 | _STD_END | ||
| 124 | |||
| 125 | /* TEST: Recursion prevention. CPP doesn't allow even 1 level of recursion. */ | ||
| 126 | #define STARTMACRO MACROA | ||
| 127 | #define MACROA MACROB | ||
| 128 | #define MACROB MACROA | ||
| 129 | |||
| 130 | int STARTMACRO () { | ||
| 131 | |||
| 132 | } | ||
| 133 | |||
| 134 | |||
| 135 | /* END */ | ||
diff --git a/test/cedet/tests/testsppreplaced.c b/test/cedet/tests/testsppreplaced.c new file mode 100644 index 00000000000..f4d8889409f --- /dev/null +++ b/test/cedet/tests/testsppreplaced.c | |||
| @@ -0,0 +1,97 @@ | |||
| 1 | /* What the SPP replace file would looklike with MACROS replaced. | ||
| 2 | */ | ||
| 3 | |||
| 4 | /* TEST: The EMU keyword doesn't screw up the function defn. */ | ||
| 5 | char parse_around_emu () | ||
| 6 | { | ||
| 7 | } | ||
| 8 | |||
| 9 | /* TEST: A simple word can be replaced in a definition. */ | ||
| 10 | float returnanfloat() | ||
| 11 | { | ||
| 12 | } | ||
| 13 | |||
| 14 | /* TEST: Punctuation an be replaced in a definition. */ | ||
| 15 | int foo::bar () | ||
| 16 | { | ||
| 17 | } | ||
| 18 | |||
| 19 | /* TEST: Multiple lexical characters in a definition */ | ||
| 20 | int mysuper::baz () | ||
| 21 | { | ||
| 22 | } | ||
| 23 | |||
| 24 | /* TEST: Macro replacement. */ | ||
| 25 | int increment (int in) { | ||
| 26 | return in+1; | ||
| 27 | } | ||
| 28 | |||
| 29 | /* TEST: Macro replacement with complex args */ | ||
| 30 | int myFcn1 (); | ||
| 31 | |||
| 32 | int myFcn2 (int a, int b); | ||
| 33 | int myFcn3 (int a, int b); | ||
| 34 | |||
| 35 | /* TEST: Multiple args to a macro. */ | ||
| 36 | struct ma_struct { int moose; int penguin; int emu; }; | ||
| 37 | |||
| 38 | /* TEST: Macro w/ args, but no body. */ | ||
| 39 | |||
| 40 | /* TEST: Not a macro with args, but close. */ | ||
| 41 | int not_with_args_fcn (moose) | ||
| 42 | { | ||
| 43 | } | ||
| 44 | |||
| 45 | /* TEST: macro w/ continuation. */ | ||
| 46 | int continuation_symbol () { }; | ||
| 47 | |||
| 48 | /* TEST: macros in a macro - tail processing */ | ||
| 49 | |||
| 50 | int tail (int q) {} | ||
| 51 | |||
| 52 | /* TEST: macros used impropertly. */ | ||
| 53 | |||
| 54 | int tail_fcn(int q); | ||
| 55 | |||
| 56 | /* TEST: feature of CPP from LSD <lsdsgster@...> */ | ||
| 57 | |||
| 58 | int __gthrw_foo (int arg1) { } | ||
| 59 | |||
| 60 | /* TEST: macros using macros */ | ||
| 61 | int foo; | ||
| 62 | |||
| 63 | /* TEST: macros with args using macros */ | ||
| 64 | int noodle(int noodle); | ||
| 65 | |||
| 66 | /* TEST: Double macro using the argument stack. */ | ||
| 67 | int that_foo(int i); | ||
| 68 | int this_foo(int i); | ||
| 69 | |||
| 70 | /* TEST: The G++ namespace macro hack. Not really part of SPP. */ | ||
| 71 | namespace baz { | ||
| 72 | |||
| 73 | int bazfnc(int b) { } | ||
| 74 | |||
| 75 | } | ||
| 76 | |||
| 77 | namespace foo { namespace bar { | ||
| 78 | |||
| 79 | int foo_bar_func(int a) { } | ||
| 80 | |||
| 81 | } | ||
| 82 | } | ||
| 83 | |||
| 84 | /* TEST: The VC++ macro hack. */ | ||
| 85 | namespace std { | ||
| 86 | |||
| 87 | int inside_std_namespace(int a) { } | ||
| 88 | |||
| 89 | } | ||
| 90 | |||
| 91 | /* TEST: Recursion prevention. CPP doesn't allow even 1 level of recursion. */ | ||
| 92 | int MACROA () { | ||
| 93 | |||
| 94 | } | ||
| 95 | |||
| 96 | |||
| 97 | /* End */ | ||
diff --git a/test/cedet/tests/teststruct.cpp b/test/cedet/tests/teststruct.cpp new file mode 100644 index 00000000000..6bc27b97208 --- /dev/null +++ b/test/cedet/tests/teststruct.cpp | |||
| @@ -0,0 +1,66 @@ | |||
| 1 | // Combinations of templates and structure inheritance. | ||
| 2 | // | ||
| 3 | // Created by Alex Ott. | ||
| 4 | |||
| 5 | template <typename DerivedT> | ||
| 6 | struct grammar { | ||
| 7 | public: | ||
| 8 | typedef grammar<DerivedT> self_t; | ||
| 9 | typedef DerivedT const& embed_t; | ||
| 10 | grammar() {} | ||
| 11 | ~grammar() { } | ||
| 12 | void use_parser() const { } | ||
| 13 | void test1() { } | ||
| 14 | }; | ||
| 15 | |||
| 16 | struct PDFbool_parser : public grammar<PDFbool_parser> { | ||
| 17 | PDFbool_parser() {} | ||
| 18 | template <typename scannerT> struct definition { | ||
| 19 | typedef typename scannerT::iterator_t iterator_t; | ||
| 20 | int top; | ||
| 21 | definition(const PDFbool_parser& /*self*/) { | ||
| 22 | return ; | ||
| 23 | } | ||
| 24 | const int start() const { | ||
| 25 | return top; | ||
| 26 | } | ||
| 27 | }; | ||
| 28 | }; | ||
| 29 | |||
| 30 | int main(void) { | ||
| 31 | PDFbool_parser PDFbool_p = PDFbool_parser(); | ||
| 32 | PDFbool_p.//-1- | ||
| 33 | ; | ||
| 34 | // #1# ("definition" "embed_t" "self_t" "test1" "use_parser") | ||
| 35 | } | ||
| 36 | |||
| 37 | // ---------------------------------------------------------------------- | ||
| 38 | |||
| 39 | template <class Derived> struct Base { | ||
| 40 | public: | ||
| 41 | void interface() | ||
| 42 | { | ||
| 43 | // ... | ||
| 44 | static_cast<Derived*>(this)->implementation(); | ||
| 45 | // ... | ||
| 46 | } | ||
| 47 | |||
| 48 | static void static_func() | ||
| 49 | { | ||
| 50 | // ... | ||
| 51 | Derived::static_sub_func(); | ||
| 52 | // ... | ||
| 53 | } | ||
| 54 | }; | ||
| 55 | |||
| 56 | struct Derived : Base<Derived> { | ||
| 57 | void implementation() { } | ||
| 58 | static void static_sub_func() { } | ||
| 59 | }; | ||
| 60 | |||
| 61 | int foo () { | ||
| 62 | Derived d; | ||
| 63 | d.//-2- | ||
| 64 | ; | ||
| 65 | // #2# ("implementation" "interface" "static_func" "static_sub_func") | ||
| 66 | } | ||
diff --git a/test/cedet/tests/testsubclass.cpp b/test/cedet/tests/testsubclass.cpp new file mode 100644 index 00000000000..30da4a85987 --- /dev/null +++ b/test/cedet/tests/testsubclass.cpp | |||
| @@ -0,0 +1,231 @@ | |||
| 1 | /* Special test file for Semantic Analyzer and complex C++ inheritance. | ||
| 2 | */ | ||
| 3 | |||
| 4 | //#include <iostream> | ||
| 5 | #include "testsubclass.hh" | ||
| 6 | |||
| 7 | void animal::moose::setFeet(int numfeet) //^1^ | ||
| 8 | { | ||
| 9 | if (numfeet > 4) { | ||
| 10 | std::cerr << "Why would a moose have more than 4 feet?" << std::endl; | ||
| 11 | return; | ||
| 12 | } | ||
| 13 | |||
| 14 | fFeet = numfeet; | ||
| 15 | } | ||
| 16 | |||
| 17 | int animal::moose::getFeet() //^2^ | ||
| 18 | { | ||
| 19 | return fFeet; | ||
| 20 | } | ||
| 21 | |||
| 22 | void animal::moose::doNothing() //^3^ | ||
| 23 | { | ||
| 24 | animal::moose foo(); | ||
| 25 | |||
| 26 | fFeet = N// -15- | ||
| 27 | ; // #15# ( "NAME1" "NAME2" "NAME3" ) | ||
| 28 | } | ||
| 29 | |||
| 30 | |||
| 31 | void deer::moose::setAntlers(bool have_antlers) //^4^ | ||
| 32 | { | ||
| 33 | fAntlers = have_antlers; | ||
| 34 | } | ||
| 35 | |||
| 36 | bool deer::moose::getAntlers() //^5^ | ||
| 37 | // %1% ( ( "testsubclass.cpp" "testsubclass.hh" ) ( "deer::moose::doSomething" "deer::moose::getAntlers" "moose" ) ) | ||
| 38 | { | ||
| 39 | return fAntlers; | ||
| 40 | } | ||
| 41 | |||
| 42 | bool i_dont_have_symrefs() | ||
| 43 | // %2% ( ("testsubclass.cpp" ) ("i_dont_have_symrefs")) | ||
| 44 | { | ||
| 45 | } | ||
| 46 | |||
| 47 | void deer::moose::doSomething() //^6^ | ||
| 48 | { | ||
| 49 | // All these functions should be identified by semantic analyzer. | ||
| 50 | getAntlers(); | ||
| 51 | setAntlers(true); | ||
| 52 | |||
| 53 | getFeet(); | ||
| 54 | setFeet(true); | ||
| 55 | |||
| 56 | doNothing(); | ||
| 57 | |||
| 58 | fSomeField = true; | ||
| 59 | |||
| 60 | fIsValid = true; | ||
| 61 | } | ||
| 62 | |||
| 63 | void deer::alces::setLatin(bool l) { | ||
| 64 | fLatin = l; | ||
| 65 | } | ||
| 66 | |||
| 67 | bool deer::alces::getLatin() { | ||
| 68 | return fLatin; | ||
| 69 | } | ||
| 70 | |||
| 71 | void deer::alces::doLatinStuff(moose moosein) { | ||
| 72 | // All these functions should be identified by semantic analyzer. | ||
| 73 | getFeet(); | ||
| 74 | setFeet(true); | ||
| 75 | |||
| 76 | getLatin(); | ||
| 77 | setLatin(true); | ||
| 78 | |||
| 79 | doNothing(); | ||
| 80 | |||
| 81 | deer::moose foo(); | ||
| 82 | |||
| 83 | |||
| 84 | } | ||
| 85 | |||
| 86 | moose deer::alces::createMoose() | ||
| 87 | { | ||
| 88 | moose MooseVariableName; | ||
| 89 | bool tmp; | ||
| 90 | int itmp; | ||
| 91 | bool fool; | ||
| 92 | int fast; | ||
| 93 | |||
| 94 | MooseVariableName = createMoose(); | ||
| 95 | |||
| 96 | doLatinStuff(MooseVariableName); | ||
| 97 | |||
| 98 | tmp = this.f// -1- | ||
| 99 | // #1# ( "fAlcesBool" "fIsValid" "fLatin" ) | ||
| 100 | ; | ||
| 101 | |||
| 102 | itmp = this.f// -2- | ||
| 103 | // #2# ( "fAlcesInt" "fGreek" "fIsProtectedInt" ) | ||
| 104 | ; | ||
| 105 | |||
| 106 | tmp = f// -3- | ||
| 107 | // #3# ( "fAlcesBool" "fIsValid" "fLatin" "fool" ) | ||
| 108 | ; | ||
| 109 | |||
| 110 | itmp = f// -4- | ||
| 111 | // #4# ( "fAlcesInt" "fGreek" "fIsProtectedInt" "fast" ) | ||
| 112 | ; | ||
| 113 | |||
| 114 | MooseVariableName = m// -5- | ||
| 115 | // #5# ( "moose" ) | ||
| 116 | |||
| 117 | return MooseVariableName; | ||
| 118 | } | ||
| 119 | |||
| 120 | /** Test Scope Changes | ||
| 121 | * | ||
| 122 | * This function is rigged to make sure the scope changes to account | ||
| 123 | * for different locations in local variable parsing. | ||
| 124 | */ | ||
| 125 | int someFunction(int mPickle) | ||
| 126 | { | ||
| 127 | moose mMoose = deer::alces::createMoose(); | ||
| 128 | |||
| 129 | if (mPickle == 1) { | ||
| 130 | |||
| 131 | int mOption1 = 2; | ||
| 132 | |||
| 133 | m// -5- | ||
| 134 | // #5# ( "mMoose" "mOption1" "mPickle" ) | ||
| 135 | ; | ||
| 136 | |||
| 137 | } else { | ||
| 138 | |||
| 139 | int mOption2 = 2; | ||
| 140 | |||
| 141 | m// -6- | ||
| 142 | // #6# ( "mMoose" "mOption2" "mPickle" ) | ||
| 143 | ; | ||
| 144 | } | ||
| 145 | |||
| 146 | } | ||
| 147 | |||
| 148 | // Thanks Ming-Wei Chang for this next example. | ||
| 149 | |||
| 150 | namespace pub_priv { | ||
| 151 | |||
| 152 | class A{ | ||
| 153 | private: | ||
| 154 | void private_a(){} | ||
| 155 | public: | ||
| 156 | void public_a(); | ||
| 157 | }; | ||
| 158 | |||
| 159 | void A::public_a() { | ||
| 160 | A other_a; | ||
| 161 | |||
| 162 | other_a.p// -7- | ||
| 163 | // #7# ( "private_a" "public_a" ) | ||
| 164 | ; | ||
| 165 | } | ||
| 166 | |||
| 167 | int some_regular_function(){ | ||
| 168 | A a; | ||
| 169 | a.p// -8- | ||
| 170 | // #8# ( "public_a" ) | ||
| 171 | ; | ||
| 172 | return 0; | ||
| 173 | } | ||
| 174 | |||
| 175 | } | ||
| 176 | |||
| 177 | |||
| 178 | /** Test Scope w/in a function (non-method) with classes using | ||
| 179 | * different levels of inheritance. | ||
| 180 | */ | ||
| 181 | int otherFunction() | ||
| 182 | { | ||
| 183 | sneaky::antelope Antelope(1); | ||
| 184 | sneaky::jackalope Jackalope(1); | ||
| 185 | sneaky::bugalope Bugalope(1); | ||
| 186 | |||
| 187 | Antelope.// -9- | ||
| 188 | // #9# ( "fAntyPublic" "fQuadPublic" "testAccess") | ||
| 189 | ; | ||
| 190 | |||
| 191 | Jackalope.// -10- | ||
| 192 | // #10# ( "fBunnyPublic" "testAccess") | ||
| 193 | ; | ||
| 194 | |||
| 195 | Jackalope// @1@ 6 | ||
| 196 | ; | ||
| 197 | Jackalope; | ||
| 198 | Jackalope; | ||
| 199 | Jackalope; | ||
| 200 | |||
| 201 | Bugalope.// -11- | ||
| 202 | // #11# ( "fBugPublic" "testAccess") | ||
| 203 | ; | ||
| 204 | Bugalope// @2@ 3 | ||
| 205 | ; | ||
| 206 | } | ||
| 207 | |||
| 208 | /** Test methods within each class for types of access to the baseclass. | ||
| 209 | */ | ||
| 210 | |||
| 211 | bool sneaky::antelope::testAccess() //^7^ | ||
| 212 | { | ||
| 213 | this.// -12- | ||
| 214 | // #12# ( "fAntyPrivate" "fAntyProtected" "fAntyPublic" "fQuadProtected" "fQuadPublic" "testAccess" ) | ||
| 215 | ; | ||
| 216 | } | ||
| 217 | |||
| 218 | bool sneaky::jackalope::testAccess() //^8^ | ||
| 219 | { | ||
| 220 | this.// -13- | ||
| 221 | // #13# ( "fBunnyPrivate" "fBunnyProtected" "fBunnyPublic" "fQuadProtected" "fQuadPublic" "testAccess" ) | ||
| 222 | ; | ||
| 223 | } | ||
| 224 | |||
| 225 | bool sneaky::bugalope::testAccess() //^9^ | ||
| 226 | { | ||
| 227 | this.// -14- | ||
| 228 | // #14# ( "fBugPrivate" "fBugProtected" "fBugPublic" "fQuadPublic" "testAccess" ) | ||
| 229 | ; | ||
| 230 | } | ||
| 231 | |||
diff --git a/test/cedet/tests/testsubclass.hh b/test/cedet/tests/testsubclass.hh new file mode 100644 index 00000000000..8c9886d55f1 --- /dev/null +++ b/test/cedet/tests/testsubclass.hh | |||
| @@ -0,0 +1,175 @@ | |||
| 1 | /* Special test file for Semantic Analyzer and complex C++ inheritance. | ||
| 2 | * | ||
| 3 | * Header file for testsubclass.cpp with class defns but no | ||
| 4 | * implementations. | ||
| 5 | */ | ||
| 6 | |||
| 7 | //#include <cmath> | ||
| 8 | // #include <stdio.h> | ||
| 9 | |||
| 10 | #ifndef TESTSUBCLASS_HH | ||
| 11 | #define TESTSUBCLASS_HH | ||
| 12 | |||
| 13 | namespace animal { | ||
| 14 | |||
| 15 | class moose { | ||
| 16 | public: | ||
| 17 | moose() : fFeet(0), | ||
| 18 | fIsValid(false) | ||
| 19 | { } | ||
| 20 | |||
| 21 | virtual void setFeet(int); | ||
| 22 | int getFeet(); | ||
| 23 | |||
| 24 | void doNothing(); | ||
| 25 | |||
| 26 | enum moose_enum { | ||
| 27 | NAME1, NAME2, NAME3 }; | ||
| 28 | |||
| 29 | |||
| 30 | protected: | ||
| 31 | |||
| 32 | bool fIsValid; | ||
| 33 | int fIsProtectedInt; | ||
| 34 | |||
| 35 | private: | ||
| 36 | int fFeet; // Usually 2 or 4. | ||
| 37 | bool fIsPrivateBool; | ||
| 38 | |||
| 39 | }; // moose | ||
| 40 | |||
| 41 | int two_prototypes(); | ||
| 42 | int two_prototypes(); | ||
| 43 | |||
| 44 | class quadruped { | ||
| 45 | public: | ||
| 46 | quadruped(int a) : fQuadPrivate(a) | ||
| 47 | { } | ||
| 48 | |||
| 49 | int fQuadPublic; | ||
| 50 | |||
| 51 | protected: | ||
| 52 | int fQuadProtected; | ||
| 53 | |||
| 54 | private: | ||
| 55 | int fQuadPrivate; | ||
| 56 | |||
| 57 | }; | ||
| 58 | |||
| 59 | } | ||
| 60 | |||
| 61 | |||
| 62 | namespace deer { | ||
| 63 | |||
| 64 | class moose : public animal::moose { | ||
| 65 | public: | ||
| 66 | moose() : fAntlers(false) | ||
| 67 | { } | ||
| 68 | |||
| 69 | void setAntlers(bool); | ||
| 70 | bool getAntlers(); | ||
| 71 | |||
| 72 | void doSomething(); | ||
| 73 | |||
| 74 | protected: | ||
| 75 | |||
| 76 | bool fSomeField; | ||
| 77 | |||
| 78 | private: | ||
| 79 | bool fAntlers; | ||
| 80 | |||
| 81 | }; | ||
| 82 | |||
| 83 | } // deer | ||
| 84 | |||
| 85 | // A second namespace of the same name will test the | ||
| 86 | // namespace merging needed to resolve deer::alces | ||
| 87 | namespace deer { | ||
| 88 | |||
| 89 | class alces : public animal::moose { | ||
| 90 | public: | ||
| 91 | alces(int lat) : fLatin(lat) | ||
| 92 | { } | ||
| 93 | |||
| 94 | void setLatin(bool); | ||
| 95 | bool getLatin(); | ||
| 96 | |||
| 97 | void doLatinStuff(moose moosein); // for completion testing | ||
| 98 | |||
| 99 | moose createMoose(); // for completion testing. | ||
| 100 | |||
| 101 | protected: | ||
| 102 | bool fAlcesBool; | ||
| 103 | int fAlcesInt; | ||
| 104 | |||
| 105 | private: | ||
| 106 | bool fLatin; | ||
| 107 | int fGreek; | ||
| 108 | }; | ||
| 109 | |||
| 110 | }; | ||
| 111 | |||
| 112 | // A third namespace with classes that does protected and private inheritance. | ||
| 113 | namespace sneaky { | ||
| 114 | |||
| 115 | class antelope : public animal::quadruped { | ||
| 116 | |||
| 117 | public: | ||
| 118 | antelope(int a) : animal::quadruped(), | ||
| 119 | fAntyProtected(a) | ||
| 120 | {} | ||
| 121 | |||
| 122 | int fAntyPublic; | ||
| 123 | |||
| 124 | bool testAccess(); | ||
| 125 | |||
| 126 | protected: | ||
| 127 | int fAntyProtected; | ||
| 128 | |||
| 129 | private : | ||
| 130 | int fAntyPrivate; | ||
| 131 | |||
| 132 | }; | ||
| 133 | |||
| 134 | class jackalope : protected animal::quadruped { | ||
| 135 | |||
| 136 | public: | ||
| 137 | jackalope(int a) : animal::quadruped(), | ||
| 138 | fBunny(a) | ||
| 139 | {} | ||
| 140 | |||
| 141 | int fBunnyPublic; | ||
| 142 | |||
| 143 | bool testAccess(); | ||
| 144 | |||
| 145 | protected: | ||
| 146 | bool fBunnyProtected; | ||
| 147 | |||
| 148 | private : | ||
| 149 | bool fBunnyPrivate; | ||
| 150 | |||
| 151 | }; | ||
| 152 | |||
| 153 | // Nothing specified means private. | ||
| 154 | class bugalope : /* private*/ animal::quadruped { | ||
| 155 | |||
| 156 | public: | ||
| 157 | bugalope(int a) : animal::quadruped(), | ||
| 158 | fBug(a) | ||
| 159 | {} | ||
| 160 | |||
| 161 | int fBugPublic; | ||
| 162 | |||
| 163 | bool testAccess(); | ||
| 164 | protected: | ||
| 165 | bool fBugProtected; | ||
| 166 | |||
| 167 | private : | ||
| 168 | bool fBugPrivate; | ||
| 169 | |||
| 170 | }; | ||
| 171 | |||
| 172 | |||
| 173 | }; | ||
| 174 | |||
| 175 | #endif | ||
diff --git a/test/cedet/tests/testtemplates.cpp b/test/cedet/tests/testtemplates.cpp new file mode 100644 index 00000000000..4ffb71c718c --- /dev/null +++ b/test/cedet/tests/testtemplates.cpp | |||
| @@ -0,0 +1,90 @@ | |||
| 1 | // Templates Test file: | ||
| 2 | // Written by 'Raf' | ||
| 3 | |||
| 4 | template <class T, int U, class V> | ||
| 5 | class read_ref { | ||
| 6 | public: | ||
| 7 | const T* read_ref_member_one( T); | ||
| 8 | const V* read_ref_member_two(); | ||
| 9 | }; | ||
| 10 | |||
| 11 | namespace NS { | ||
| 12 | template <class T, int U, class V> | ||
| 13 | class ref { | ||
| 14 | public: | ||
| 15 | read_ref<T,10,V> operator->() { | ||
| 16 | m_// -1- | ||
| 17 | ; | ||
| 18 | // #1# ( "m_datas" ) | ||
| 19 | } | ||
| 20 | |||
| 21 | private: | ||
| 22 | T m_datas[U]; | ||
| 23 | }; | ||
| 24 | |||
| 25 | } | ||
| 26 | |||
| 27 | class FooOne { | ||
| 28 | public: | ||
| 29 | int fooOneMember(); | ||
| 30 | }; | ||
| 31 | |||
| 32 | class FooTwo { | ||
| 33 | public: | ||
| 34 | int fooTwoMember(); | ||
| 35 | }; | ||
| 36 | |||
| 37 | class FooThree { | ||
| 38 | public: | ||
| 39 | int fooThreeMember(); | ||
| 40 | |||
| 41 | FooOne * operator->(); | ||
| 42 | }; | ||
| 43 | |||
| 44 | typedef ref<FooOne, 10,FooTwo> Test; | ||
| 45 | |||
| 46 | using NS; | ||
| 47 | |||
| 48 | void | ||
| 49 | main(void) { | ||
| 50 | ref<FooOne, 10, FooTwo> v; | ||
| 51 | |||
| 52 | v->read_ref_member_one()-> // -2- | ||
| 53 | ; | ||
| 54 | // #2# ( "fooOneMember" ) | ||
| 55 | |||
| 56 | v->read_ref_member_two()-> // -3- | ||
| 57 | ; | ||
| 58 | // #3# ( "fooTwoMember" ) | ||
| 59 | |||
| 60 | v-> // -4- | ||
| 61 | ; | ||
| 62 | // #4# ( "read_ref_member_one" "read_ref_member_two" ) | ||
| 63 | |||
| 64 | Test t; | ||
| 65 | |||
| 66 | t->read_ref_member_two()-> // -5- | ||
| 67 | ; | ||
| 68 | // #5# ( "fooTwoMember" ) | ||
| 69 | |||
| 70 | ref<FooOne, 10, FooThree> v2; | ||
| 71 | |||
| 72 | v2->read_ref_member_two()-> // -6- | ||
| 73 | ; | ||
| 74 | // #6# ( "fooOneMember" ) | ||
| 75 | |||
| 76 | /* Try all these things by also specifying the namespace in the name. */ | ||
| 77 | NS::ref<FooOne, 10, FooTwo> v3; | ||
| 78 | |||
| 79 | v3->read_ref_member_one()-> // -7- | ||
| 80 | ; | ||
| 81 | // #7# ( "fooOneMember" ) | ||
| 82 | |||
| 83 | v3->read_ref_member_two()-> // -8- | ||
| 84 | ; | ||
| 85 | // #8# ( "fooTwoMember" ) | ||
| 86 | |||
| 87 | v3->read_ref_member_two// @1@ 5 | ||
| 88 | ; | ||
| 89 | |||
| 90 | } | ||
diff --git a/test/cedet/tests/testtypedefs.cpp b/test/cedet/tests/testtypedefs.cpp new file mode 100644 index 00000000000..35965a6ad60 --- /dev/null +++ b/test/cedet/tests/testtypedefs.cpp | |||
| @@ -0,0 +1,74 @@ | |||
| 1 | // Sample with some fake bits out of std::string | ||
| 2 | // | ||
| 3 | // Thanks Ming-Wei Chang for these examples. | ||
| 4 | |||
| 5 | namespace std { | ||
| 6 | |||
| 7 | template <T>class basic_string { | ||
| 8 | |||
| 9 | public: | ||
| 10 | void resize(int); | ||
| 11 | |||
| 12 | }; | ||
| 13 | |||
| 14 | } | ||
| 15 | |||
| 16 | typedef std::basic_string<char> mstring; | ||
| 17 | |||
| 18 | using namespace std; | ||
| 19 | typedef basic_string<char> bstring; | ||
| 20 | |||
| 21 | |||
| 22 | int main(){ | ||
| 23 | mstring a; | ||
| 24 | |||
| 25 | a.// -1- | ||
| 26 | ; | ||
| 27 | // #1# ( "resize" ) | ||
| 28 | |||
| 29 | bstring b; | ||
| 30 | // It doesn't work here. | ||
| 31 | b.// -2- | ||
| 32 | ; | ||
| 33 | // #2# ( "resize" ) | ||
| 34 | |||
| 35 | return 0; | ||
| 36 | } | ||
| 37 | |||
| 38 | |||
| 39 | // ------------------ | ||
| 40 | |||
| 41 | class Bar | ||
| 42 | { | ||
| 43 | public: | ||
| 44 | void someFunc() {} | ||
| 45 | |||
| 46 | }; | ||
| 47 | |||
| 48 | typedef Bar new_Bar; | ||
| 49 | |||
| 50 | template <class mytype> | ||
| 51 | class TBar | ||
| 52 | { | ||
| 53 | public: | ||
| 54 | void otherFunc() {} | ||
| 55 | |||
| 56 | }; | ||
| 57 | |||
| 58 | typedef TBar<char> new_TBar; | ||
| 59 | |||
| 60 | int main() | ||
| 61 | { | ||
| 62 | new_Bar nb; | ||
| 63 | new_TBar ntb; | ||
| 64 | |||
| 65 | nb.// -3- | ||
| 66 | ; | ||
| 67 | // #3# ("someFunc") | ||
| 68 | |||
| 69 | ntb.// -4- | ||
| 70 | ; | ||
| 71 | // #4# ("otherFunc") | ||
| 72 | |||
| 73 | return 0; | ||
| 74 | } | ||
diff --git a/test/cedet/tests/testusing.cpp b/test/cedet/tests/testusing.cpp new file mode 100644 index 00000000000..b35f3a13063 --- /dev/null +++ b/test/cedet/tests/testusing.cpp | |||
| @@ -0,0 +1,132 @@ | |||
| 1 | // Test using statements in C++ | ||
| 2 | |||
| 3 | #include <adstdio.h> | ||
| 4 | |||
| 5 | #include <testusing.hh> | ||
| 6 | |||
| 7 | namespace moose { | ||
| 8 | |||
| 9 | class MyClass; | ||
| 10 | class Point; | ||
| 11 | |||
| 12 | typedef MyClass snerk; | ||
| 13 | } | ||
| 14 | |||
| 15 | namespace moose { | ||
| 16 | |||
| 17 | class Point; | ||
| 18 | class MyClass; | ||
| 19 | |||
| 20 | } | ||
| 21 | |||
| 22 | namespace { | ||
| 23 | |||
| 24 | int global_variable = 0; | ||
| 25 | |||
| 26 | }; | ||
| 27 | |||
| 28 | using moose::MyClass; | ||
| 29 | |||
| 30 | void someFcn() { | ||
| 31 | |||
| 32 | MyClass f; | ||
| 33 | |||
| 34 | f.//-1- | ||
| 35 | ; //#1# ( "getVal" "setVal" ) | ||
| 36 | |||
| 37 | } | ||
| 38 | |||
| 39 | // Code from Zhiqiu Kong | ||
| 40 | |||
| 41 | namespace panda { | ||
| 42 | |||
| 43 | using namespace bread_name; | ||
| 44 | |||
| 45 | int func() | ||
| 46 | { | ||
| 47 | bread test; | ||
| 48 | test.//-2- | ||
| 49 | ;// #2# ( "geta" ) | ||
| 50 | return 0; | ||
| 51 | } | ||
| 52 | } | ||
| 53 | |||
| 54 | // Local using statements and aliased types | ||
| 55 | // Code from David Engster | ||
| 56 | |||
| 57 | void func2() | ||
| 58 | { | ||
| 59 | using namespace somestuff; | ||
| 60 | OneClass f; | ||
| 61 | f.//-3- | ||
| 62 | ; //#3# ( "aFunc" "anInt" ) | ||
| 63 | } | ||
| 64 | |||
| 65 | void func3() | ||
| 66 | { | ||
| 67 | using somestuff::OneClass; | ||
| 68 | OneClass f; | ||
| 69 | f.//-4- | ||
| 70 | ; //#4# ( "aFunc" "anInt" ) | ||
| 71 | } | ||
| 72 | |||
| 73 | // Dereferencing alias types created through 'using' statements | ||
| 74 | |||
| 75 | // Alias with fully qualified name | ||
| 76 | void func4() | ||
| 77 | { | ||
| 78 | otherstuff::OneClass f; | ||
| 79 | f. //-5- | ||
| 80 | ; //#5# ( "aFunc" "anInt" ) | ||
| 81 | } | ||
| 82 | |||
| 83 | // Alias through namespace directive | ||
| 84 | void func5() | ||
| 85 | { | ||
| 86 | using namespace otherstuff; | ||
| 87 | OneClass f; | ||
| 88 | f. //-6- | ||
| 89 | ; //#6# ( "aFunc" "anInt" ) | ||
| 90 | } | ||
| 91 | |||
| 92 | // Check name hiding | ||
| 93 | void func6() | ||
| 94 | { | ||
| 95 | using namespace morestuff; | ||
| 96 | OneClass f; // Alias for somestuff::OneClass | ||
| 97 | f. //-7- | ||
| 98 | ; //#7# ( "aFunc" "anInt" ) | ||
| 99 | aStruct g; // This however is morestuff::aStruct ! | ||
| 100 | g. //-8- | ||
| 101 | ; //#8# ( "anotherBar" "anotherFoo" ) | ||
| 102 | } | ||
| 103 | |||
| 104 | // Alias of an alias | ||
| 105 | // Currently doesn't work interactively for some reason. | ||
| 106 | void func6() | ||
| 107 | { | ||
| 108 | using namespace evenmorestuff; | ||
| 109 | OneClass f; | ||
| 110 | f. //-7- | ||
| 111 | ; //#7# ( "aFunc" "anInt" ) | ||
| 112 | } | ||
| 113 | |||
| 114 | // Alias for struct in nested namespace, fully qualified | ||
| 115 | void func7() | ||
| 116 | { | ||
| 117 | outer::StructNested f; | ||
| 118 | f.//-8- | ||
| 119 | ; //#8# ( "one" "two" ) | ||
| 120 | } | ||
| 121 | |||
| 122 | // Alias for nested namespace | ||
| 123 | void func8() | ||
| 124 | { | ||
| 125 | using namespace outerinner; | ||
| 126 | StructNested f; | ||
| 127 | AnotherStruct g; | ||
| 128 | f.//-9- | ||
| 129 | ; //#9# ( "one" "two" ) | ||
| 130 | g.//-10- | ||
| 131 | ; //#10# ( "four" "three" ) | ||
| 132 | } | ||
diff --git a/test/cedet/tests/testusing.hh b/test/cedet/tests/testusing.hh new file mode 100644 index 00000000000..d8b4e905531 --- /dev/null +++ b/test/cedet/tests/testusing.hh | |||
| @@ -0,0 +1,125 @@ | |||
| 1 | // test usings header file. | ||
| 2 | |||
| 3 | namespace moose { | ||
| 4 | |||
| 5 | class Point; | ||
| 6 | |||
| 7 | class MyClass; | ||
| 8 | |||
| 9 | } | ||
| 10 | |||
| 11 | |||
| 12 | namespace moose { | ||
| 13 | |||
| 14 | class Point; | ||
| 15 | |||
| 16 | class MyClass { | ||
| 17 | public: | ||
| 18 | MyClass() : fVal(0) { | ||
| 19 | } | ||
| 20 | |||
| 21 | ~MyClass() {}; | ||
| 22 | |||
| 23 | /** | ||
| 24 | * fVal Accessors | ||
| 25 | * @{ | ||
| 26 | */ | ||
| 27 | int getVal() const { | ||
| 28 | return fVal; | ||
| 29 | } | ||
| 30 | void setVal(int Val) const { | ||
| 31 | fVal = Val; | ||
| 32 | } | ||
| 33 | /** | ||
| 34 | * @} | ||
| 35 | */ | ||
| 36 | private: | ||
| 37 | int fVal; | ||
| 38 | }; | ||
| 39 | |||
| 40 | } | ||
| 41 | |||
| 42 | namespace deer { | ||
| 43 | |||
| 44 | class Pickle; | ||
| 45 | |||
| 46 | }; | ||
| 47 | |||
| 48 | // Code from Zhiqiu Kong | ||
| 49 | |||
| 50 | #ifndef BREAD_H | ||
| 51 | #define BREAD_H | ||
| 52 | |||
| 53 | namespace bread_name { | ||
| 54 | class bread | ||
| 55 | { | ||
| 56 | public: | ||
| 57 | void geta(); | ||
| 58 | private: | ||
| 59 | int m_a; | ||
| 60 | int m_b; | ||
| 61 | }; | ||
| 62 | } | ||
| 63 | |||
| 64 | #endif | ||
| 65 | |||
| 66 | // Code from David Engster | ||
| 67 | // Creating alias types through 'using' trickery | ||
| 68 | |||
| 69 | namespace somestuff { | ||
| 70 | class OneClass { | ||
| 71 | public: | ||
| 72 | void aFunc(); | ||
| 73 | int anInt; | ||
| 74 | }; | ||
| 75 | struct aStruct { | ||
| 76 | int foo; | ||
| 77 | int bar; | ||
| 78 | }; | ||
| 79 | } | ||
| 80 | |||
| 81 | namespace otherstuff { | ||
| 82 | // make otherstuff::OneClass an alias for somestuff::OneClass | ||
| 83 | using somestuff::OneClass; | ||
| 84 | } | ||
| 85 | |||
| 86 | namespace morestuff { | ||
| 87 | // make morestuff an alias namespace for somestuff | ||
| 88 | using namespace somestuff; | ||
| 89 | // but hide aStruct with own type | ||
| 90 | struct aStruct { | ||
| 91 | int anotherFoo; | ||
| 92 | int anotherBar; | ||
| 93 | }; | ||
| 94 | } | ||
| 95 | |||
| 96 | // We can also create an alias for an alias | ||
| 97 | namespace evenmorestuff { | ||
| 98 | using otherstuff::OneClass; | ||
| 99 | } | ||
| 100 | |||
| 101 | // Now with nested namespaces | ||
| 102 | namespace outer { | ||
| 103 | namespace inner { | ||
| 104 | struct StructNested { | ||
| 105 | int one; | ||
| 106 | int two; | ||
| 107 | }; | ||
| 108 | struct AnotherStruct { | ||
| 109 | int three; | ||
| 110 | int four; | ||
| 111 | }; | ||
| 112 | } | ||
| 113 | } | ||
| 114 | |||
| 115 | // Elevate the first struct into 'outer' | ||
| 116 | // so that we can access it via 'outer::StructNested' | ||
| 117 | namespace outer { | ||
| 118 | using outer::inner::StructNested; | ||
| 119 | } | ||
| 120 | |||
| 121 | // Create an alias for a nested namespace | ||
| 122 | namespace outerinner { | ||
| 123 | // equivalent to 'namespace outerinner = outer::inner;' | ||
| 124 | using namespace outer::inner; | ||
| 125 | } | ||
diff --git a/test/cedet/tests/testvarnames.c b/test/cedet/tests/testvarnames.c new file mode 100644 index 00000000000..5e576fd0328 --- /dev/null +++ b/test/cedet/tests/testvarnames.c | |||
| @@ -0,0 +1,71 @@ | |||
| 1 | /* | ||
| 2 | * Test variable and function names, lists of variables on one line, etc. | ||
| 3 | */ | ||
| 4 | |||
| 5 | struct independent { | ||
| 6 | int indep_1; | ||
| 7 | int indep_2; | ||
| 8 | }; | ||
| 9 | |||
| 10 | struct independent var_indep_struct; | ||
| 11 | |||
| 12 | struct { | ||
| 13 | int unnamed_1; | ||
| 14 | int unnamed_2; | ||
| 15 | } var_unamed_struct; | ||
| 16 | |||
| 17 | struct { | ||
| 18 | int unnamed_3; | ||
| 19 | int unnamed_4; | ||
| 20 | } var_un_2, var_un_3; | ||
| 21 | |||
| 22 | struct inlinestruct { | ||
| 23 | int named_1; | ||
| 24 | int named_2; | ||
| 25 | } var_named_struct; | ||
| 26 | |||
| 27 | struct inline2struct { | ||
| 28 | int named_3; | ||
| 29 | int named_4; | ||
| 30 | } var_n_2, var_n_3; | ||
| 31 | |||
| 32 | /* Structures with names that then declare variables | ||
| 33 | * should also be completable. | ||
| 34 | * | ||
| 35 | * Getting this to work is the bugfix in semantic-c.el CVS v 1.122 | ||
| 36 | */ | ||
| 37 | struct inlinestruct in_var1; | ||
| 38 | struct inline2struct in_var2; | ||
| 39 | |||
| 40 | int test_1(int var_arg1) { | ||
| 41 | |||
| 42 | var_// -1- | ||
| 43 | ; // #1# ("var_arg1" "var_indep_struct" "var_n_2" "var_n_3" "var_named_struct" "var_un_2" "var_un_3" "var_unamed_struct") | ||
| 44 | |||
| 45 | var_indep_struct.// -2- | ||
| 46 | ; // #2# ( "indep_1" "indep_2" ) | ||
| 47 | |||
| 48 | var_unamed_struct.// -3- | ||
| 49 | ; // #3# ( "unnamed_1" "unnamed_2" ) | ||
| 50 | |||
| 51 | var_named_struct.// -4- | ||
| 52 | ; // #4# ( "named_1" "named_2" ) | ||
| 53 | |||
| 54 | var_un_2.// -5- | ||
| 55 | ; // #5# ( "unnamed_3" "unnamed_4" ) | ||
| 56 | var_un_3.// -6- | ||
| 57 | ; // #6# ( "unnamed_3" "unnamed_4" ) | ||
| 58 | |||
| 59 | var_n_2.// -7- | ||
| 60 | ; // #7# ( "named_3" "named_4" ) | ||
| 61 | var_n_3.// -8- | ||
| 62 | ; // #8# ( "named_3" "named_4" ) | ||
| 63 | |||
| 64 | in_// -9- | ||
| 65 | ; // #9# ( "in_var1" "in_var2" ) | ||
| 66 | |||
| 67 | in_var1.// -10- | ||
| 68 | ; // #10# ( "named_1" "named_2") | ||
| 69 | in_var2.// -11- | ||
| 70 | ; // #11# ( "named_3" "named_4") | ||
| 71 | } | ||