diff options
author | Chong Yidong <cyd@stupidchicken.com> | 2009-09-28 23:23:31 +0000 |
---|---|---|
committer | Chong Yidong <cyd@stupidchicken.com> | 2009-09-28 23:23:31 +0000 |
commit | 74ea13c1a8d63e4f4015e2b9e7e4336e546e7e4a (patch) | |
tree | d895d7e93cf93022f48bd6d173f616f1bb4b99fc /test | |
parent | b9de0a4665563f847bc7c94f8c89180bf2a9f6bd (diff) | |
download | emacs-74ea13c1a8d63e4f4015e2b9e7e4336e546e7e4a.tar.gz |
Add CEDET tests.
Diffstat (limited to 'test')
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 @@ +;;; cedet-utests.el --- Run all unit tests in the CEDET suite. + +;; Copyright (C) 2008, 2009 Free Software Foundation, Inc. + +;; Author: Eric M. Ludlam <eric@siege-engine.com> + +;; This file is part of GNU Emacs. + +;; GNU Emacs is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; GNU Emacs is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. + +;;; Commentary: +;; +;; Remembering to run all the unit tests available in CEDET one at a +;; time is a bit time consuming. This links all the tests together +;; into one command. + +(require 'cedet) +;;; Code: +(defvar cedet-utest-test-alist + '( + ;; + ;; COMMON + ;; + + ;; Test inversion + ("inversion" . inversion-unit-test) + + ;; EZ Image dumping. + ("ezimage associations" . ezimage-image-association-dump) + ("ezimage images" . ezimage-image-dump) + + ;; Pulse + ("pulse interactive test" . (lambda () (pulse-test t))) + + ;; Files + ("cedet file conversion" . cedet-files-utest) + + ;; + ;; EIEIO + ;; + ("eieio" . (lambda () (let ((lib (locate-library "eieio-tests.el" + t))) + (load-file lib)))) + ("eieio: browser" . eieio-browse) + ("eieio: custom" . (lambda () + (require 'eieio-custom) + (customize-variable 'eieio-widget-test))) + ("eieio: chart" . (lambda () + (if (cedet-utest-noninteractive) + (message " ** Skipping test in noninteractive mode.") + (chart-test-it-all)))) + ;; + ;; EDE + ;; + + ;; @todo - Currently handled in the integration tests. Need + ;; some simpler unit tests here. + + ;; + ;; SEMANTIC + ;; + ("semantic: lex spp table write" . semantic-lex-spp-write-utest) + ("semantic: multi-lang parsing" . semantic-utest-main) + ("semantic: C preprocessor" . semantic-utest-c) + ("semantic: analyzer tests" . semantic-ia-utest) + ("semanticdb: data cache" . semantic-test-data-cache) + ("semantic: throw-on-input" . + (lambda () + (if (cedet-utest-noninteractive) + (message " ** Skipping test in noninteractive mode.") + (semantic-test-throw-on-input)))) + + ("semantic: gcc: output parse test" . semantic-gcc-test-output-parser) + ;; + ;; SRECODE + ;; + ("srecode: fields" . srecode-field-utest) + ("srecode: templates" . srecode-utest-template-output) + ("srecode: show maps" . srecode-get-maps) + ("srecode: getset" . srecode-utest-getset-output) + ) + "Alist of all the tests in CEDET we should run.") + +(defvar cedet-running-master-tests nil + "Non-nil when CEDET-utest is running all the tests.") + +(defun cedet-utest (&optional exit-on-error) + "Run the CEDET unittests. +EXIT-ON-ERROR causes the test suite to exit on an error, instead +of just logging the error." + (interactive) + (if (or (not (featurep 'semanticdb-mode)) + (not (semanticdb-minor-mode-p))) + (error "CEDET Tests require: M-x semantic-load-enable-minimum-features")) + (cedet-utest-log-setup "ALL TESTS") + (let ((tl cedet-utest-test-alist) + (notes nil) + (err nil) + (start (current-time)) + (end nil) + (cedet-running-master-tests t) + ) + (dolist (T tl) + (cedet-utest-add-log-item-start (car T)) + (setq notes nil err nil) + (condition-case Cerr + (progn + (funcall (cdr T)) + ) + (error + (setq err (format "ERROR: %S" Cerr)) + ;;(message "Error caught: %s" Cerr) + )) + + ;; Cleanup stray input and events that are in the way. + ;; Not doing this causes sit-for to not refresh the screen. + ;; Doing this causes the user to need to press keys more frequently. + (when (and (interactive-p) (input-pending-p)) + (if (fboundp 'read-event) + (read-event) + (read-char))) + + (cedet-utest-add-log-item-done notes err) + (when (and exit-on-error err) + (message "to debug this test point, execute:") + (message "%S" (cdr T)) + (message "\n ** Exiting Test Suite. ** \n") + (throw 'cedet-utest-exit-on-error t) + ) + ) + (setq end (current-time)) + (cedet-utest-log-shutdown-msg "ALL TESTS" start end) + nil)) + +(defun cedet-utest-noninteractive () + "Return non-nil if running non-interactively." + (if (featurep 'xemacs) + (noninteractive) + noninteractive)) + +;;;###autoload +(defun cedet-utest-batch () + "Run the CEDET unit test in BATCH mode." + (unless (cedet-utest-noninteractive) + (error "`cedet-utest-batch' is to be used only with -batch")) + (condition-case err + (when (catch 'cedet-utest-exit-on-error + ;; Get basic semantic features up. + (semantic-load-enable-minimum-features) + ;; Disables all caches related to semantic DB so all + ;; tests run as if we have bootstrapped CEDET for the + ;; first time. + (setq-default semanticdb-new-database-class 'semanticdb-project-database) + (message "Disabling existing Semantic Database Caches.") + + ;; Disabling the srecoder map, we won't load a pre-existing one + ;; and will be forced to bootstrap a new one. + (setq srecode-map-save-file nil) + + ;; Run the tests + (cedet-utest t) + ) + (kill-emacs 1)) + (error + (error "Error in unit test harness:\n %S" err)) + ) + ) + +;;; Logging utility. +;; +(defvar cedet-utest-frame nil + "Frame used during cedet unit test logging.") +(defvar cedet-utest-buffer nil + "Frame used during cedet unit test logging.") +(defvar cedet-utest-frame-parameters + '((name . "CEDET-UTEST") + (width . 80) + (height . 25) + (minibuffer . t)) + "Frame parameters used for the cedet utest log frame.") + +(defvar cedet-utest-last-log-item nil + "Remember the last item we were logging for.") + +(defvar cedet-utest-log-timer nil + "During a test, track the start time.") + +(defun cedet-utest-log-setup (&optional title) + "Setup a frame and buffer for unit testing. +Optional argument TITLE is the title of this testing session." + (setq cedet-utest-log-timer (current-time)) + (if (cedet-utest-noninteractive) + (message "\n>> Setting up %s tests to run @ %s\n" + (or title "") + (current-time-string)) + + ;; Interactive mode needs a frame and buffer. + (when (or (not cedet-utest-frame) (not (frame-live-p cedet-utest-frame))) + (setq cedet-utest-frame (make-frame cedet-utest-frame-parameters))) + (when (or (not cedet-utest-buffer) (not (buffer-live-p cedet-utest-buffer))) + (setq cedet-utest-buffer (get-buffer-create "*CEDET utest log*"))) + (save-excursion + (set-buffer cedet-utest-buffer) + (setq cedet-utest-last-log-item nil) + (when (not cedet-running-master-tests) + (erase-buffer)) + (insert "\n\nSetting up " + (or title "") + " tests to run @ " (current-time-string) "\n\n")) + (let ((oframe (selected-frame))) + (unwind-protect + (progn + (select-frame cedet-utest-frame) + (switch-to-buffer cedet-utest-buffer t)) + (select-frame oframe))) + )) + +(defun cedet-utest-elapsed-time (start end) + "Copied from elp.el. Was elp-elapsed-time. +Argument START and END bound the time being calculated." + (+ (* (- (car end) (car start)) 65536.0) + (- (car (cdr end)) (car (cdr start))) + (/ (- (car (cdr (cdr end))) (car (cdr (cdr start)))) 1000000.0))) + +(defun cedet-utest-log-shutdown (title &optional errorcondition) + "Shut-down a larger test suite. +TITLE is the section that is done. +ERRORCONDITION is some error that may have occured durinig testing." + (let ((endtime (current-time)) + ) + (cedet-utest-log-shutdown-msg title cedet-utest-log-timer endtime) + (setq cedet-utest-log-timer nil) + )) + +(defun cedet-utest-log-shutdown-msg (title startime endtime) + "Show a shutdown message with TITLE, STARTIME, and ENDTIME." + (if (cedet-utest-noninteractive) + (progn + (message "\n>> Test Suite %s ended at @ %s" + title + (format-time-string "%c" endtime)) + (message " Elapsed Time %.2f Seconds\n" + (cedet-utest-elapsed-time startime endtime))) + + (save-excursion + (set-buffer cedet-utest-buffer) + (goto-char (point-max)) + (insert "\n>> Test Suite " title " ended at @ " + (format-time-string "%c" endtime) "\n" + " Elapsed Time " + (number-to-string + (cedet-utest-elapsed-time startime endtime)) + " Seconds\n * ")) + )) + +(defun cedet-utest-show-log-end () + "Show the end of the current unit test log." + (unless (cedet-utest-noninteractive) + (let* ((cb (current-buffer)) + (cf (selected-frame)) + (bw (or (get-buffer-window cedet-utest-buffer t) + (get-buffer-window (switch-to-buffer cedet-utest-buffer) t))) + (lf (window-frame bw)) + ) + (select-frame lf) + (select-window bw) + (goto-char (point-max)) + (select-frame cf) + (set-buffer cb) + ))) + +(defun cedet-utest-post-command-hook () + "Hook run after the current log command was run." + (if (cedet-utest-noninteractive) + (message "") + (save-excursion + (set-buffer cedet-utest-buffer) + (goto-char (point-max)) + (insert "\n\n"))) + (setq cedet-utest-last-log-item nil) + (remove-hook 'post-command-hook 'cedet-utest-post-command-hook) + ) + +(defun cedet-utest-add-log-item-start (item) + "Add ITEM into the log as being started." + (unless (equal item cedet-utest-last-log-item) + (setq cedet-utest-last-log-item item) + ;; This next line makes sure we clear out status during logging. + (add-hook 'post-command-hook 'cedet-utest-post-command-hook) + + (if (cedet-utest-noninteractive) + (message " - Running %s ..." item) + (save-excursion + (set-buffer cedet-utest-buffer) + (goto-char (point-max)) + (when (not (bolp)) (insert "\n")) + (insert "Running " item " ... ") + (sit-for 0) + )) + (cedet-utest-show-log-end) + )) + +(defun cedet-utest-add-log-item-done (&optional notes err precr) + "Add into the log that the last item is done. +Apply NOTES to the doneness of the log. +Apply ERR if there was an error in previous item. +Optional argument PRECR indicates to prefix the done msg w/ a newline." + (if (cedet-utest-noninteractive) + ;; Non-interactive-mode - show a message. + (if notes + (message " * %s {%s}" (or err "done") notes) + (message " * %s" (or err "done"))) + ;; Interactive-mode - insert into the buffer. + (save-excursion + (set-buffer cedet-utest-buffer) + (goto-char (point-max)) + (when precr (insert "\n")) + (if err + (insert err) + (insert "done") + (when notes (insert " (" notes ")"))) + (insert "\n") + (setq cedet-utest-last-log-item nil) + (sit-for 0) + ))) + +;;; INDIVIDUAL TEST API +;; +;; Use these APIs to start and log information. +;; +;; The other fcns will be used to log across all the tests at once. +(defun cedet-utest-log-start (testname) + "Setup the log for the test TESTNAME." + ;; Make sure we have a log buffer. + (save-window-excursion + (when (or (not cedet-utest-buffer) + (not (buffer-live-p cedet-utest-buffer)) + (not (get-buffer-window cedet-utest-buffer t)) + ) + (cedet-utest-log-setup)) + ;; Add our startup message. + (cedet-utest-add-log-item-start testname) + )) + +(defun cedet-utest-log(format &rest args) + "Log the text string FORMAT. +The rest of the ARGS are used to fill in FORMAT with `format'." + (if (cedet-utest-noninteractive) + (apply 'message format args) + (save-excursion + (set-buffer cedet-utest-buffer) + (goto-char (point-max)) + (when (not (bolp)) (insert "\n")) + (insert (apply 'format format args)) + (insert "\n") + (sit-for 0) + )) + (cedet-utest-show-log-end) + ) + +;;; Inversion tests + +(defun inversion-unit-test () + "Test inversion to make sure it can identify different version strings." + (interactive) + (let ((c1 (inversion-package-version 'inversion)) + (c1i (inversion-package-incompatibility-version 'inversion)) + (c2 (inversion-decode-version "1.3alpha2")) + (c3 (inversion-decode-version "1.3beta4")) + (c4 (inversion-decode-version "1.3 beta5")) + (c5 (inversion-decode-version "1.3.4")) + (c6 (inversion-decode-version "2.3alpha")) + (c7 (inversion-decode-version "1.3")) + (c8 (inversion-decode-version "1.3pre1")) + (c9 (inversion-decode-version "2.4 (patch 2)")) + (c10 (inversion-decode-version "2.4 (patch 3)")) + (c11 (inversion-decode-version "2.4.2.1")) + (c12 (inversion-decode-version "2.4.2.2")) + ) + (if (not (and + (inversion-= c1 c1) + (inversion-< c1i c1) + (inversion-< c2 c3) + (inversion-< c3 c4) + (inversion-< c4 c5) + (inversion-< c5 c6) + (inversion-< c2 c4) + (inversion-< c2 c5) + (inversion-< c2 c6) + (inversion-< c3 c5) + (inversion-< c3 c6) + (inversion-< c7 c6) + (inversion-< c4 c7) + (inversion-< c2 c7) + (inversion-< c8 c6) + (inversion-< c8 c7) + (inversion-< c4 c8) + (inversion-< c2 c8) + (inversion-< c9 c10) + (inversion-< c10 c11) + (inversion-< c11 c12) + ;; Negatives + (not (inversion-< c3 c2)) + (not (inversion-< c4 c3)) + (not (inversion-< c5 c4)) + (not (inversion-< c6 c5)) + (not (inversion-< c7 c2)) + (not (inversion-< c7 c8)) + (not (inversion-< c12 c11)) + ;; Test the tester on inversion + (not (inversion-test 'inversion inversion-version)) + ;; Test that we throw an error + (inversion-test 'inversion "0.0.0") + (inversion-test 'inversion "1000.0") + )) + (error "Inversion tests failed") + (message "Inversion tests passed.")))) + +;;; cedet-files unit test + +(defvar cedet-files-utest-list + '( + ( "/home/me/src/myproj/src/foo.c" . "!home!me!src!myproj!src!foo.c" ) + ( "c:/work/myproj/foo.el" . "!drive_c!work!myproj!foo.el" ) + ( "//windows/proj/foo.java" . "!!windows!proj!foo.java" ) + ( "/home/me/proj!bang/foo.c" . "!home!me!proj!!bang!foo.c" ) + ) + "List of different file names to test. +Each entry is a cons cell of ( FNAME . CONVERTED ) +where FNAME is some file name, and CONVERTED is what it should be +converted into.") + +(defun cedet-files-utest () + "Test out some file name conversions." + (interactive) + (let ((idx 0)) + (dolist (FT cedet-files-utest-list) + + (setq idx (+ idx 1)) + + (let ((dir->file (cedet-directory-name-to-file-name (car FT) t)) + (file->dir (cedet-file-name-to-directory-name (cdr FT) t)) + ) + + (unless (string= (cdr FT) dir->file) + (error "Failed: %d. Found: %S Wanted: %S" + idx dir->file (cdr FT)) + ) + + (unless (string= file->dir (car FT)) + (error "Failed: %d. Found: %S Wanted: %S" + idx file->dir (car FT))))))) + +;;; pulse test + +(defun pulse-test (&optional no-error) + "Test the lightening function for pulsing a line. +When optional NO-ERROR Don't throw an error if we can't run tests." + (interactive) + (if (or (not pulse-flag) (not (pulse-available-p))) + (if no-error + nil + (error (concat "Pulse test only works on versions of Emacs" + " that support pulsing"))) + ;; Run the tests + (when (interactive-p) + (message "<Press a key> Pulse one line.") + (read-char)) + (pulse-momentary-highlight-one-line (point)) + (when (interactive-p) + (message "<Press a key> Pulse a region.") + (read-char)) + (pulse-momentary-highlight-region (point) + (save-excursion + (condition-case nil + (forward-char 30) + (error nil)) + (point))) + (when (interactive-p) + (message "<Press a key> Pulse line a specific color.") + (read-char)) + (pulse-momentary-highlight-one-line (point) 'modeline) + (when (interactive-p) + (message "<Press a key> Pulse a pre-existing overlay.") + (read-char)) + (let* ((start (point-at-bol)) + (end (save-excursion + (end-of-line) + (when (not (eobp)) + (forward-char 1)) + (point))) + (o (make-overlay start end)) + ) + (pulse-momentary-highlight-overlay o) + (if (overlay-buffer o) + (delete-overlay o) + (error "Non-temporary overlay was deleted!")) + ) + (when (interactive-p) + (message "Done!")))) + +(provide 'cedet-utests) + +;;; 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 @@ +;;; From ede-locate: + +(require 'ede/locate) + +;;; TESTS +;; +;; Some testing routines. +(defun ede-locate-test-locate (file) + "Test EDE Locate on FILE using LOCATE type. +The search is done with the current EDE root." + (interactive "sFile: ") + (let ((loc (ede-locate-locate + "test" + :root (ede-project-root-directory + (ede-toplevel))))) + (data-debug-new-buffer "*EDE Locate ADEBUG*") + (ede-locate-file-in-project loc file) + (data-debug-insert-object-slots loc "]")) + ) + +(defun ede-locate-test-global (file) + "Test EDE Locate on FILE using GNU Global type. +The search is done with the current EDE root." + (interactive "sFile: ") + (let ((loc (ede-locate-global + "test" + :root (ede-project-root-directory + (ede-toplevel))))) + (data-debug-new-buffer "*EDE Locate ADEBUG*") + (ede-locate-file-in-project loc file) + (data-debug-insert-object-slots loc "]")) + ) + +(defun ede-locate-test-idutils (file) + "Test EDE Locate on FILE using ID Utils type. +The search is done with the current EDE root." + (interactive "sFile: ") + (let ((loc (ede-locate-idutils + "test" + :root (ede-project-root-directory + (ede-toplevel))))) + (data-debug-new-buffer "*EDE Locate ADEBUG*") + (ede-locate-file-in-project loc file) + (data-debug-insert-object-slots loc "]")) + ) + +(defun ede-locate-test-cscope (file) + "Test EDE Locate on FILE using CScope type. +The search is done with the current EDE root." + (interactive "sFile: ") + (let ((loc (ede-locate-cscope + "test" + :root (ede-project-root-directory + (ede-toplevel))))) + (data-debug-new-buffer "*EDE Locate ADEBUG*") + (ede-locate-file-in-project loc file) + (data-debug-insert-object-slots loc "]")) + ) 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 @@ +;;; semantic-ia-utest.el --- Analyzer unit tests + +;; Copyright (C) 2008, 2009 Free Software Foundation, Inc. + +;; Author: Eric M. Ludlam <eric@siege-engine.com> + +;; This file is part of GNU Emacs. + +;; GNU Emacs is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; GNU Emacs is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. + +;;; Commentary: +;; +;; Use marked-up files in the test directory and run the analyzer +;; on them. Make sure the answers are correct. +;; +;; Each file has cursor keys in them of the form: +;; // -#- ("ans1" "ans2" ) +;; where # is 1, 2, 3, etc, and some sort of answer list. + +;;; Code: +(require 'semantic) +(require 'semantic/analyze) +(require 'semantic/analyze/refs) +(require 'semantic/symref) +(require 'semantic/symref/filter) + +(load-file "cedet-utests.el") + +(defvar semantic-ia-utest-file-list + '( + "tests/testdoublens.cpp" + "tests/testsubclass.cpp" + "tests/testtypedefs.cpp" + "tests/teststruct.cpp" + "tests/testtemplates.cpp" + "tests/testfriends.cpp" + "tests/testusing.cpp" + "tests/testnsp.cpp" + "tests/testsppcomplete.c" + "tests/testvarnames.c" + "tests/testjavacomp.java" + ) + "List of files with analyzer completion test points.") + +(defvar semantic-ia-utest-error-log-list nil + "List of errors occuring during a run.") + +;;;###autoload +(defun semantic-ia-utest (&optional arg) + "Run the semantic ia unit test against stored sources. +Argument ARG specifies which set of tests to run. + 1 - ia utests + 2 - regs utests + 3 - symrefs utests + 4 - symref count utests" + (interactive "P") + (save-excursion + + (let ((fl semantic-ia-utest-file-list) + (semantic-ia-utest-error-log-list nil) + ) + + (cedet-utest-log-setup "ANALYZER") + + (set-buffer (semantic-find-file-noselect + (or (locate-library "semantic-ia-utest.el") + "semantic-ia-utest.el"))) + + (while fl + + ;; Make sure we have the files we think we have. + (when (not (file-exists-p (car fl))) + (error "Cannot find unit test file: %s" (car fl))) + + ;; Run the tests. + (let ((fb (find-buffer-visiting (car fl))) + (b (semantic-find-file-noselect (car fl) t))) + + ;; Run the test on it. + (save-excursion + (set-buffer b) + + ;; This line will also force the include, scope, and typecache. + (semantic-clear-toplevel-cache) + ;; Force tags to be parsed. + (semantic-fetch-tags) + + (semantic-ia-utest-log " ** Starting tests in %s" + (buffer-name)) + + (when (or (not arg) (= arg 1)) + (semantic-ia-utest-buffer)) + + (when (or (not arg) (= arg 2)) + (set-buffer b) + (semantic-ia-utest-buffer-refs)) + + (when (or (not arg) (= arg 3)) + (set-buffer b) + (semantic-sr-utest-buffer-refs)) + + (when (or (not arg) (= arg 4)) + (set-buffer b) + (semantic-src-utest-buffer-refs)) + + (semantic-ia-utest-log " ** Completed tests in %s\n" + (buffer-name)) + ) + + ;; If it wasn't already in memory, whack it. + (when (not fb) + (kill-buffer b)) + ) + (setq fl (cdr fl))) + + (cedet-utest-log-shutdown + "ANALYZER" + (when semantic-ia-utest-error-log-list + (format "%s Failures found." + (length semantic-ia-utest-error-log-list)))) + (when semantic-ia-utest-error-log-list + (error "Failures found during analyzer unit tests")) + )) + ) + +(defun semantic-ia-utest-buffer () + "Run analyzer completion unit-test pass in the current buffer." + + (let* ((idx 1) + (regex-p nil) + (regex-a nil) + (p nil) + (a nil) + (pass nil) + (fail nil) + (actual nil) + (desired nil) + ;; Exclude unpredictable system files in the + ;; header include list. + (semanticdb-find-default-throttle + (remq 'system semanticdb-find-default-throttle)) + ) + ;; Keep looking for test points until we run out. + (while (save-excursion + (setq regex-p (concat "//\\s-*-" (number-to-string idx) "-" ) + regex-a (concat "//\\s-*#" (number-to-string idx) "#" )) + (goto-char (point-min)) + (save-match-data + (when (re-search-forward regex-p nil t) + (setq p (match-beginning 0)))) + (save-match-data + (when (re-search-forward regex-a nil t) + (setq a (match-end 0)))) + (and p a)) + + (save-excursion + + (goto-char p) + + (let* ((ctxt (semantic-analyze-current-context)) + (acomp + (condition-case nil + (semantic-analyze-possible-completions ctxt) + (error nil)))) + (setq actual (mapcar 'semantic-tag-name acomp))) + + (goto-char a) + + (let ((bss (buffer-substring-no-properties (point) (point-at-eol)))) + (condition-case nil + (setq desired (read bss)) + (error (setq desired (format " FAILED TO PARSE: %S" + bss))))) + + (if (equal actual desired) + (setq pass (cons idx pass)) + (setq fail (cons idx fail)) + (semantic-ia-utest-log + " Failed %d. Desired: %S Actual %S" + idx desired actual) + (add-to-list 'semantic-ia-utest-error-log-list + (list (buffer-name) idx desired actual) + ) + + ) + ) + + (setq p nil a nil) + (setq idx (1+ idx))) + + (if fail + (progn + (semantic-ia-utest-log + " Unit tests (completions) failed tests %S" + (reverse fail)) + ) + (semantic-ia-utest-log " Unit tests (completions) passed (%d total)" + (- idx 1))) + + )) + +(defun semantic-ia-utest-buffer-refs () + "Run a analyze-refs unit-test pass in the current buffer." + + (let* ((idx 1) + (regex-p nil) + (p nil) + (pass nil) + (fail nil) + ;; Exclude unpredictable system files in the + ;; header include list. + (semanticdb-find-default-throttle + (remq 'system semanticdb-find-default-throttle)) + ) + ;; Keep looking for test points until we run out. + (while (save-excursion + (setq regex-p (concat "//\\s-*\\^" (number-to-string idx) "^" ) + ) + (goto-char (point-min)) + (save-match-data + (when (re-search-forward regex-p nil t) + (setq p (match-beginning 0)))) + p) + + (save-excursion + + (goto-char p) + (forward-char -1) + + (let* ((ct (semantic-current-tag)) + (refs (semantic-analyze-tag-references ct)) + (impl (semantic-analyze-refs-impl refs t)) + (proto (semantic-analyze-refs-proto refs t)) + (pf nil) + ) + (setq + pf + (catch 'failed + (if (and impl proto (car impl) (car proto)) + (let (ct2 ref2 impl2 proto2 + newstart) + (cond + ((semantic-equivalent-tag-p (car impl) ct) + ;; We are on an IMPL. Go To the proto, and find matches. + (semantic-go-to-tag (car proto)) + (setq newstart (car proto)) + ) + ((semantic-equivalent-tag-p (car proto) ct) + ;; We are on a PROTO. Go to the imple, and find matches + (semantic-go-to-tag (car impl)) + (setq newstart (car impl)) + ) + (t + ;; No matches is a fail. + (throw 'failed t) + )) + ;; Get the new tag, does it match? + (setq ct2 (semantic-current-tag)) + + ;; Does it match? + (when (not (semantic-equivalent-tag-p ct2 newstart)) + (throw 'failed t)) + + ;; Can we double-jump? + (setq ref2 (semantic-analyze-tag-references ct) + impl2 (semantic-analyze-refs-impl ref2 t) + proto2 (semantic-analyze-refs-proto ref2 t)) + + (when (or (not (and impl2 proto2)) + (not + (and (semantic-equivalent-tag-p + (car impl) (car impl2)) + (semantic-equivalent-tag-p + (car proto) (car proto2))))) + (throw 'failed t)) + ) + + ;; Else, no matches at all, so another fail. + (throw 'failed t) + ))) + + (if (not pf) + ;; We passed + (setq pass (cons idx pass)) + ;; We failed. + (setq fail (cons idx fail)) + (semantic-ia-utest-log + " Failed %d. For %s (Num impls %d) (Num protos %d)" + idx (if ct (semantic-tag-name ct) "<No tag found>") + (length impl) (length proto)) + (add-to-list 'semantic-ia-utest-error-log-list + (list (buffer-name) idx) + ) + )) + + (setq p nil) + (setq idx (1+ idx)) + + )) + + (if fail + (progn + (semantic-ia-utest-log + " Unit tests (refs) failed tests") + ) + (semantic-ia-utest-log " Unit tests (refs) passed (%d total)" + (- idx 1))) + + )) + +(defun semantic-sr-utest-buffer-refs () + "Run a symref unit-test pass in the current buffer." + + ;; This line will also force the include, scope, and typecache. + (semantic-clear-toplevel-cache) + ;; Force tags to be parsed. + (semantic-fetch-tags) + + (let* ((idx 1) + (tag nil) + (regex-p nil) + (desired nil) + (actual-result nil) + (actual nil) + (pass nil) + (fail nil) + (symref-tool-used nil) + ;; Exclude unpredictable system files in the + ;; header include list. + (semanticdb-find-default-throttle + (remq 'system semanticdb-find-default-throttle)) + ) + ;; Keep looking for test points until we run out. + (while (save-excursion + (setq regex-p (concat "//\\s-*\\%" (number-to-string idx) "%" ) + ) + (goto-char (point-min)) + (save-match-data + (when (re-search-forward regex-p nil t) + (setq tag (semantic-current-tag)) + (goto-char (match-end 0)) + (setq desired (read (buffer-substring (point) (point-at-eol)))) + )) + tag) + + (setq actual-result (semantic-symref-find-references-by-name + (semantic-tag-name tag) 'target + 'symref-tool-used)) + + (if (not actual-result) + (progn + (setq fail (cons idx fail)) + (semantic-ia-utest-log + " Failed FNames %d: No results." idx) + (semantic-ia-utest-log + " Failed Tool: %s" (object-name symref-tool-used)) + + (add-to-list 'semantic-ia-utest-error-log-list + (list (buffer-name) idx) + ) + ) + + (setq actual (list (sort (mapcar + 'file-name-nondirectory + (semantic-symref-result-get-files actual-result)) + 'string<) + (sort + (mapcar + 'semantic-format-tag-canonical-name + (semantic-symref-result-get-tags actual-result)) + 'string<))) + + + (if (equal desired actual) + ;; We passed + (setq pass (cons idx pass)) + ;; We failed. + (setq fail (cons idx fail)) + (when (not (equal (car actual) (car desired))) + (semantic-ia-utest-log + " Failed FNames %d: Actual: %S Desired: %S" + idx (car actual) (car desired)) + (semantic-ia-utest-log + " Failed Tool: %s" (object-name symref-tool-used)) + ) + (when (not (equal (car (cdr actual)) (car (cdr desired)))) + (semantic-ia-utest-log + " Failed TNames %d: Actual: %S Desired: %S" + idx (car (cdr actual)) (car (cdr desired))) + (semantic-ia-utest-log + " Failed Tool: %s" (object-name symref-tool-used)) + ) + (add-to-list 'semantic-ia-utest-error-log-list + (list (buffer-name) idx) + ) + )) + + (setq idx (1+ idx)) + (setq tag nil)) + + (if fail + (progn + (semantic-ia-utest-log + " Unit tests (symrefs) failed tests") + ) + (semantic-ia-utest-log " Unit tests (symrefs) passed (%d total)" + (- idx 1))) + + )) + +(defun semantic-src-utest-buffer-refs () + "Run a sym-ref counting unit-test pass in the current buffer." + + ;; This line will also force the include, scope, and typecache. + (semantic-clear-toplevel-cache) + ;; Force tags to be parsed. + (semantic-fetch-tags) + + (let* ((idx 1) + (start nil) + (regex-p nil) + (desired nil) + (actual nil) + (pass nil) + (fail nil) + ;; Exclude unpredictable system files in the + ;; header include list. + (semanticdb-find-default-throttle + (remq 'system semanticdb-find-default-throttle)) + ) + ;; Keep looking for test points until we run out. + (while (save-excursion + (setq regex-p (concat "//\\s-*@" + (number-to-string idx) + "@\\s-+\\(\\w+\\)" )) + (goto-char (point-min)) + (save-match-data + (when (re-search-forward regex-p nil t) + (goto-char (match-beginning 1)) + (setq desired (read (buffer-substring (point) (point-at-eol)))) + (setq start (match-beginning 0)) + (goto-char start) + (setq actual (semantic-symref-test-count-hits-in-tag)) + start))) + + (if (not actual) + (progn + (setq fail (cons idx fail)) + (semantic-ia-utest-log + " Failed symref count %d: No results." idx) + + (add-to-list 'semantic-ia-utest-error-log-list + (list (buffer-name) idx) + ) + ) + + (if (equal desired actual) + ;; We passed + (setq pass (cons idx pass)) + ;; We failed. + (setq fail (cons idx fail)) + (when (not (equal actual desired)) + (semantic-ia-utest-log + " Failed symref count %d: Actual: %S Desired: %S" + idx actual desired) + ) + + (add-to-list 'semantic-ia-utest-error-log-list + (list (buffer-name) idx) + ) + )) + + (setq idx (1+ idx)) + ) + + (if fail + (progn + (semantic-ia-utest-log + " Unit tests (symrefs counter) failed tests") + ) + (semantic-ia-utest-log " Unit tests (symrefs counter) passed (%d total)" + (- idx 1))) + + )) + +(defun semantic-ia-utest-start-log () + "Start up a testlog for a run." + ;; Redo w/ CEDET utest framework. + (cedet-utest-log-start "semantic: analyzer tests")) + +(defun semantic-ia-utest-log (&rest args) + "Log some test results. +Pass ARGS to format to create the log message." + ;; Forward to CEDET utest framework. + (apply 'cedet-utest-log args)) + +(provide 'semantic-ia-utest) +;;; 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 @@ +;;; semantic-utest.el --- Miscellaneous Semantic tests. + +;;; Copyright (C) 2003, 2004, 2007, 2008, 2009 Free Software Foundation, Inc. + +;; Author: Eric M. Ludlam <zappo@gnu.org> + +;; This file is part of GNU Emacs. + +;; GNU Emacs is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; GNU Emacs is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. + +;;; Commentary: + +;; Originally, there are many test functions scattered among the +;; Semantic source files. This file consolidates them. + +(require 'data-debug) + +;;; From semantic-complete + +(require 'semantic/complete) + +(defun semantic-complete-test () + "Test completion mechanisms." + (interactive) + (message "%S" + (semantic-format-tag-prototype + (semantic-complete-read-tag-project "Symbol: ")))) + +;;; From semanticdb-ebrowse + +(require 'semantic/db-ebrowse) + +(defun semanticdb-ebrowse-run-tests () + "Run some tests of the semanticdb-ebrowse system. +All systems are different. Ask questions along the way." + (interactive) + (let ((doload nil)) + (when (y-or-n-p "Create a system database to test with? ") + (call-interactively 'semanticdb-create-ebrowse-database) + (setq doload t)) + ;; Should we load in caches + (when (if doload + (y-or-n-p "New database created. Reload system databases? ") + (y-or-n-p "Load in all system databases? ")) + (semanticdb-load-ebrowse-caches))) + ;; Ok, databases were creatd. Lets try some searching. + (when (not (or (eq major-mode 'c-mode) + (eq major-mode 'c++-mode))) + (error "Please make your default buffer be a C or C++ file, then +run the test again.."))) + +(defun semanticdb-ebrowse-dump () + "Find the first loaded ebrowse table, and dump out the contents." + (interactive) + (let ((db semanticdb-database-list) + (ab nil)) + (while db + (when (semanticdb-project-database-ebrowse-p (car db)) + (setq ab (data-debug-new-buffer "*EBROWSE Database*")) + (data-debug-insert-thing (car db) "*" "") + (setq db nil) + ) + (setq db (cdr db))))) + +;;; From semanticdb-global: + +(require 'semantic/db-global) + +(defvar semanticdb-test-gnu-global-startfile "~/src/global-5.7.3/global/global.c" + "File to use for testing.") + +(defun semanticdb-test-gnu-global (searchfor &optional standardfile) + "Test the GNU Global semanticdb. +Argument SEARCHFOR is the text to search for. +If optional arg STANDARDFILE is non nil, use a standard file w/ global enabled." + (interactive "sSearch For Tag: \nP") + + (require 'data-debug) + (save-excursion + (when standardfile + (save-match-data + (set-buffer (find-file-noselect semanticdb-test-gnu-global-startfile)))) + + (condition-case err + (semanticdb-enable-gnu-global-in-buffer) + (error (if standardfile + (error err) + (save-match-data + (set-buffer (find-file-noselect semanticdb-test-gnu-global-startfile))) + (semanticdb-enable-gnu-global-in-buffer)))) + + (let* ((db (semanticdb-project-database-global "global")) + (tab (semanticdb-file-table db (buffer-file-name))) + (result (semanticdb-deep-find-tags-for-completion-method tab searchfor)) + ) + (data-debug-new-buffer "*SemanticDB Gnu Global Result*") + (data-debug-insert-thing result "?" "")))) + +;;; From semantic-find + +(require 'semantic/find) + +(defun semantic-find-benchmark () + "Run some simple benchmarks to see how we are doing. +Optional argument ARG is the number of iterations to run." + (interactive) + (require 'benchmark) + (let ((f-name nil) + (b-name nil) + (f-comp) + (b-comp) + (f-regex) + ) + (garbage-collect) + (setq f-name + (benchmark-run-compiled + 1000 (semantic-find-first-tag-by-name "class3" + "test/test.cpp"))) + (garbage-collect) + (setq b-name + (benchmark-run-compiled + 1000 (semantic-brute-find-first-tag-by-name "class3" + "test/test.cpp"))) + (garbage-collect) + (setq f-comp + (benchmark-run-compiled + 1000 (semantic-find-tags-for-completion "method" + "test/test.cpp"))) + (garbage-collect) + (setq b-comp + (benchmark-run-compiled + 1000 (semantic-brute-find-tag-by-name-regexp "^method" + "test/test.cpp"))) + (garbage-collect) + (setq f-regex + (benchmark-run-compiled + 1000 (semantic-find-tags-by-name-regexp "^method" + "test/test.cpp"))) + + (message "Name [new old] [ %.3f %.3f ] Complete [newc/new old] [ %.3f/%.3f %.3f ]" + (car f-name) (car b-name) + (car f-comp) (car f-regex) + (car b-comp)) + )) + +;;; From semantic-format + +(require 'semantic/format) + +(defun semantic-test-all-format-tag-functions (&optional arg) + "Test all outputs from `semantic-format-tag-functions'. +Output is generated from the function under `point'. +Optional argument ARG specifies not to use color." + (interactive "P") + (semantic-fetch-tags) + (let* ((tag (semantic-current-tag)) + (par (semantic-current-tag-parent)) + (fns semantic-format-tag-functions)) + (with-output-to-temp-buffer "*format-tag*" + (princ "Tag->format function tests:") + (while fns + (princ "\n") + (princ (car fns)) + (princ ":\n ") + (let ((s (funcall (car fns) tag par (not arg)))) + (save-excursion + (set-buffer "*format-tag*") + (goto-char (point-max)) + (insert s))) + (setq fns (cdr fns)))) + )) + +;;; From semantic-fw: + +(require 'semantic/fw) + +(defun semantic-test-data-cache () + "Test the data cache." + (interactive) + (let ((data '(a b c))) + (save-excursion + (set-buffer (get-buffer-create " *semantic-test-data-cache*")) + (erase-buffer) + (insert "The Moose is Loose") + (goto-char (point-min)) + (semantic-cache-data-to-buffer (current-buffer) (point) (+ (point) 5) + data 'moose 'exit-cache-zone) + (if (equal (semantic-get-cache-data 'moose) data) + (message "Successfully retrieved cached data.") + (error "Failed to retrieve cached data"))))) + +(defun semantic-test-throw-on-input () + "Test that throw on input will work." + (interactive) + (semantic-throw-on-input 'done-die) + (message "Exit Code: %s" + (semantic-exit-on-input 'testing + (let ((inhibit-quit nil) + (message-log-max nil)) + (while t + (message "Looping ... press a key to test") + (semantic-throw-on-input 'test-inner-loop)) + 'exit))) + (when (input-pending-p) + (if (fboundp 'read-event) + (read-event) + (read-char)))) + +;;; From semantic-idle: + +(require 'semantic/idle) + +(defun semantic-idle-pnf-test () + "Test `semantic-idle-scheduler-work-parse-neighboring-files' and time it." + (interactive) + (let ((start (current-time)) + (junk (semantic-idle-scheduler-work-parse-neighboring-files)) + (end (current-time))) + (message "Work took %.2f seconds." (semantic-elapsed-time start end)))) + +;;; From semantic-lex: + +(require 'semantic/lex) + +(defun semantic-lex-test-full-depth (arg) + "Test the semantic lexer in the current buffer parsing through lists. +Usually the lexer parses +If universal argument ARG, then try the whole buffer." + (interactive "P") + (let* ((start (current-time)) + (result (semantic-lex + (if arg (point-min) (point)) + (point-max) + 100)) + (end (current-time))) + (message "Elapsed Time: %.2f seconds." + (semantic-elapsed-time start end)) + (pop-to-buffer "*Lexer Output*") + (require 'pp) + (erase-buffer) + (insert (pp-to-string result)) + (goto-char (point-min)))) + +(defun semantic-lex-test-region (beg end) + "Test the semantic lexer in the current buffer. +Analyze the area between BEG and END." + (interactive "r") + (let ((result (semantic-lex beg end))) + (pop-to-buffer "*Lexer Output*") + (require 'pp) + (erase-buffer) + (insert (pp-to-string result)) + (goto-char (point-min)))) + +;;; From semantic-lex-spp: + +(require 'semantic/lex-spp) + +(defun semantic-lex-spp-write-test () + "Test the semantic tag writer against the current buffer." + (interactive) + (with-output-to-temp-buffer "*SPP Write Test*" + (semantic-lex-spp-table-write-slot-value + (semantic-lex-spp-save-table)))) + +(defun semantic-lex-spp-write-utest () + "Unit test using the test spp file to test the slot write fcn." + (interactive) + (let* ((sem (locate-library "semantic-lex-spp.el")) + (dir (file-name-directory sem))) + (save-excursion + (set-buffer (find-file-noselect + (expand-file-name "tests/testsppreplace.c" + dir))) + (semantic-lex-spp-write-test)))) + +;;; From semantic-tag-write: + +;;; TESTING. + +(require 'semantic/tag-write) + +(defun semantic-tag-write-test () + "Test the semantic tag writer against the tag under point." + (interactive) + (with-output-to-temp-buffer "*Tag Write Test*" + (semantic-tag-write-one-tag (semantic-current-tag)))) + +(defun semantic-tag-write-list-test () + "Test the semantic tag writer against the tag under point." + (interactive) + (with-output-to-temp-buffer "*Tag Write Test*" + (semantic-tag-write-tag-list (semantic-fetch-tags)))) + +;;; From semantic-symref-filter: + +(require 'semantic/symref/filter) + +(defun semantic-symref-test-count-hits-in-tag () + "Lookup in the current tag the symbol under point. +the count all the other references to the same symbol within the +tag that contains point, and return that." + (interactive) + (let* ((ctxt (semantic-analyze-current-context)) + (target (car (reverse (oref ctxt prefix)))) + (tag (semantic-current-tag)) + (start (current-time)) + (Lcount 0)) + (when (semantic-tag-p target) + (semantic-symref-hits-in-region + target (lambda (start end prefix) (setq Lcount (1+ Lcount))) + (semantic-tag-start tag) + (semantic-tag-end tag)) + (when (interactive-p) + (message "Found %d occurances of %s in %.2f seconds" + Lcount (semantic-tag-name target) + (semantic-elapsed-time start (current-time)))) + Lcount))) + +;;; From bovine-gcc: + +(require 'semantic/bovine/gcc) + +;; Example output of "gcc -v" +(defvar semantic-gcc-test-strings + '(;; My old box: + "Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.2.2/specs +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 +Thread model: posix +gcc version 3.2.2 20030222 (Red Hat Linux 3.2.2-5)" + ;; Alex Ott: + "Using built-in specs. +Target: i486-linux-gnu +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 +Thread model: posix +gcc version 4.3.1 (Ubuntu 4.3.1-9ubuntu1)" + ;; My debian box: + "Using built-in specs. +Target: x86_64-unknown-linux-gnu +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 +Thread model: posix +gcc version 4.2.3" + ;; My mac: + "Using built-in specs. +Target: i686-apple-darwin8 +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 +Thread model: posix +gcc version 4.0.1 (Apple Computer, Inc. build 5341)" + ;; Ubuntu Intrepid + "Using built-in specs. +Target: x86_64-linux-gnu +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 +Thread model: posix +gcc version 4.3.2 (Ubuntu 4.3.2-1ubuntu12)" + ;; Red Hat EL4 + "Reading specs from /usr/lib/gcc/x86_64-redhat-linux/3.4.6/specs +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 +Thread model: posix +gcc version 3.4.6 20060404 (Red Hat 3.4.6-10)" + ;; Red Hat EL5 + "Using built-in specs. +Target: x86_64-redhat-linux +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 +Thread model: posix +gcc version 4.1.2 20080704 (Red Hat 4.1.2-44)" + ;; David Engster's german gcc on ubuntu 4.3 + "Es werden eingebaute Spezifikationen verwendet. +Ziel: i486-linux-gnu +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 +Thread-Modell: posix +gcc-Version 4.3.2 (Ubuntu 4.3.2-1ubuntu12)" + ;; Damien Deville bsd + "Using built-in specs. +Target: i386-undermydesk-freebsd +Configured with: FreeBSD/i386 system compiler +Thread model: posix +gcc version 4.2.1 20070719 [FreeBSD]" + ) + "A bunch of sample gcc -v outputs from different machines.") + +(defvar semantic-gcc-test-strings-fail + '(;; A really old solaris box I found + "Reading specs from /usr/local/gcc-2.95.2/lib/gcc-lib/sparc-sun-solaris2.6/2.95.2/specs +gcc version 2.95.2 19991024 (release)" + ) + "A bunch of sample gcc -v outputs that fail to provide the info we want.") + +(defun semantic-gcc-test-output-parser () + "Test the output parser against some collected strings." + (interactive) + (let ((fail nil)) + (dolist (S semantic-gcc-test-strings) + (let* ((fields (semantic-gcc-fields S)) + (v (cdr (assoc 'version fields))) + (h (or (cdr (assoc 'target fields)) + (cdr (assoc '--target fields)) + (cdr (assoc '--host fields)))) + (p (cdr (assoc '--prefix fields))) + ) + ;; No longer test for prefixes. + (when (not (and v h)) + (let ((strs (split-string S "\n"))) + (message "Test failed on %S\nV H P:\n%S %S %S" (car strs) v h p)) + (setq fail t)) + )) + (dolist (S semantic-gcc-test-strings-fail) + (let* ((fields (semantic-gcc-fields S)) + (v (cdr (assoc 'version fields))) + (h (or (cdr (assoc '--host fields)) + (cdr (assoc 'target fields)))) + (p (cdr (assoc '--prefix fields))) + ) + (when (and v h p) + (message "Negative test failed on %S" S) + (setq fail t)) + )) + (if (not fail) (message "Tests passed.")) + )) + +(defun semantic-gcc-test-output-parser-this-machine () + "Test the output parser against the machine currently running Emacs." + (interactive) + (let ((semantic-gcc-test-strings (list (semantic-gcc-query "gcc" "-v")))) + (semantic-gcc-test-output-parser)) + ) 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 @@ +;;; semantic-utest-c.el --- C based parsing tests. + +;; Copyright (C) 2008, 2009 Eric M. Ludlam + +;; Author: Eric M. Ludlam <eric@siege-engine.com> +;; X-RCS: $Id: semantic-utest-c.el,v 1.1.2.1 2009/09/20 04:00:16 cyd Exp $ + +;; This program is free software; you can redistribute it and/or +;; modify it under the terms of the GNU General Public License as +;; published by the Free Software Foundation; either version 2, or (at +;; your option) any later version. + +;; This program is distributed in the hope that it will be useful, but +;; WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +;; General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program; see the file COPYING. If not, write to +;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +;; Boston, MA 02110-1301, USA. + +;;; Commentary: +;; +;; Run some C based parsing tests. + +(require 'semantic) + +(defvar semantic-utest-c-comparisons + '( ("testsppreplace.c" . "testsppreplaced.c") + ) + "List of files to parse and compare against eachother.") + +;;; Code: +;;;###autoload +(defun semantic-utest-c () + "Run parsing test for C from the test directory." + (interactive) + (dolist (fp semantic-utest-c-comparisons) + (let* ((sem (locate-library "semantic")) + (sdir (file-name-directory sem)) + (semantic-lex-c-nested-namespace-ignore-second nil) + (tags-actual + (save-excursion + (set-buffer (find-file-noselect (expand-file-name (concat "tests/" (car fp)) sdir))) + (semantic-clear-toplevel-cache) + (semantic-fetch-tags))) + (tags-expected + (save-excursion + (set-buffer (find-file-noselect (expand-file-name (concat "tests/" (cdr fp)) sdir))) + (semantic-clear-toplevel-cache) + (semantic-fetch-tags)))) + ;; Now that we have the tags, compare them for SPP accuracy. + (dolist (tag tags-actual) + (if (and (semantic-tag-of-class-p tag 'variable) + (semantic-tag-variable-constant-p tag)) + nil ; skip the macros. + (if (semantic-tag-similar-with-subtags-p tag (car tags-expected)) + (setq tags-expected (cdr tags-expected)) + (with-mode-local c-mode + (error "Found: >> %s << Expected: >> %s <<" + (semantic-format-tag-prototype tag nil t) + (semantic-format-tag-prototype (car tags-expected) nil t) + ))) + )) + ;; Passed? + (message "PASSED!") + ))) + + +(provide 'semantic-utest-c) +;;; 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 @@ +;;; semantic-utest.el --- Tests for semantic's parsing system. + +;;; Copyright (C) 2003, 2004, 2007, 2008, 2009 Free Software Foundation, Inc. + +;; Author: Eric M. Ludlam <zappo@gnu.org> + +;; This file is part of GNU Emacs. + +;; GNU Emacs is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; GNU Emacs is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. + +;;; Commentary: +;; +;; Semantic's parsing and partial parsing system is pretty complex. +;; These unit tests attempt to emulate semantic's partial reparsing +;; and full reparsing system, and anything else I may feel the urge +;; to write a test for. + +(require 'semantic) + +(load-file "cedet-utests.el") + +(defvar semantic-utest-temp-directory (if (fboundp 'temp-directory) + (temp-directory) + temporary-file-directory) + "Temporary directory to use when creating files.") + +(defun semantic-utest-fname (name) + "Create a filename for NAME in /tmp." + (expand-file-name name semantic-utest-temp-directory)) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Data for C tests + +(defvar semantic-utest-C-buffer-contents + "/* Test file for C language for Unit Tests */ + +#include <stdio.h> +#include \"sutest.h\" + +struct mystruct1 { + int slot11; + char slot12; + float slot13; +}; + +int var1; + +float funp1(char arg11, char arg12); + +char fun2(int arg_21, int arg_22) /*1*/ +{ + struct mystruct1 *ms1 = malloc(sizeof(struct mystruct1)); + + char sv = calc_sv(var1); + + if (var1 == 0) { + sv = 1; + } else if (arg_21 == 0) { + sv = 2; + } else if (arg_22 == 0) { + sv = 3; + } else { + sv = 4; + } + + printf(\"SV = %d\\n\", sv); + + /* Memory Leak */ + ms1.slot1 = sv; + + return 'A' + sv; +} +" + "Contents of a C buffer initialized by this unit test. +Be sure to change `semantic-utest-C-name-contents' when you +change this variable.") + +(defvar semantic-utest-C-h-buffer-contents + "/* Test file for C language header file for Unit Tests */ + +int calc_sv(int); + +" + "Contents of a C header file buffer initialized by this unit test.") + +(defvar semantic-utest-C-filename (semantic-utest-fname "sutest.c") + "File to open and erase during this test for C.") + +(defvar semantic-utest-C-filename-h + (concat (file-name-sans-extension semantic-utest-C-filename) + ".h") + "Header file filename for C") + + +(defvar semantic-utest-C-name-contents + '(("stdio.h" include + (:system-flag t) + nil (overlay 48 66 "sutest.c")) + ("sutest.h" include nil nil (overlay 67 86 "sutest.c")) + ("mystruct1" type + (:members + (("slot11" variable + (:type "int") + (reparse-symbol classsubparts) + (overlay 109 120 "sutest.c")) + ("slot12" variable + (:type "char") + (reparse-symbol classsubparts) + (overlay 123 135 "sutest.c")) + ("slot13" variable + (:type "float") + (reparse-symbol classsubparts) + (overlay 138 151 "sutest.c"))) + :type "struct") + nil (overlay 88 154 "sutest.c")) + ("var1" variable + (:type "int") + nil (overlay 156 165 "sutest.c")) + ("funp1" function + (:prototype-flag t :arguments + (("arg11" variable + (:type "char") + (reparse-symbol arg-sub-list) + (overlay 179 190 "sutest.c")) + ("arg12" variable + (:type "char") + (reparse-symbol arg-sub-list) + (overlay 191 202 "sutest.c"))) + :type "float") + nil (overlay 167 203 "sutest.c")) + ("fun2" function + (:arguments + (("arg_21" variable + (:type "int") + (reparse-symbol arg-sub-list) + (overlay 215 226 "sutest.c")) + ("arg_22" variable + (:type "int") + (reparse-symbol arg-sub-list) + (overlay 227 238 "sutest.c"))) + :type "char") + nil (overlay 205 566 "sutest.c"))) + "List of expected tag names for C.") + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Data for Python tests + +(defvar semantic-utest-Python-buffer-contents +" +def fun1(a,b,c): + return a + +def fun2(a,b,c): #1 + return b + +" + + +) +; "pyhon test case. notice that python is indentation sensitive + + +(defvar semantic-utest-Python-name-contents + '(("fun1" function + (:arguments + (("a" variable nil + (reparse-symbol function_parameters) + (overlay 10 11 "tst.py")) + ("b" variable nil + (reparse-symbol function_parameters) + (overlay 12 13 "tst.py")) + ("c" variable nil + (reparse-symbol function_parameters) + (overlay 14 15 "tst.py")))) + nil (overlay 1 31 "tst.py")) + ("fun2" function + (:arguments + (("a" variable nil + (reparse-symbol function_parameters) + (overlay 41 42 "tst.py")) + ("b" variable nil + (reparse-symbol function_parameters) + (overlay 43 44 "tst.py")) + ("c" variable nil + (reparse-symbol function_parameters) + (overlay 45 46 "tst.py")))) + nil (overlay 32 65 "tst.py"))) + + "List of expected tag names for Python.") + + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Data for Java tests + +(defvar semantic-utest-Java-buffer-contents +" +class JavaTest{ + void fun1(int a,int b){ + return a; + } + + void fun2(int a,int b){ //1 + return b; + } + +} +" +) + +(defvar semantic-utest-Java-name-contents + '(("JavaTest" type + (:members + (("fun1" function + (:arguments + (("a" variable + (:type "int") + (reparse-symbol formal_parameters) + (overlay 30 35 "JavaTest.java")) + ("b" variable + (:type "int") + (reparse-symbol formal_parameters) + (overlay 36 41 "JavaTest.java"))) + :type "void") + (reparse-symbol class_member_declaration) + (overlay 20 61 "JavaTest.java")) + ("fun2" function + (:arguments + (("a" variable + (:type "int") + (reparse-symbol formal_parameters) + (overlay 75 80 "JavaTest.java")) + ("b" variable + (:type "int") + (reparse-symbol formal_parameters) + (overlay 81 86 "JavaTest.java"))) + :type "void") + (reparse-symbol class_member_declaration) + (overlay 65 110 "JavaTest.java"))) + :type "class") + nil (overlay 2 113 "JavaTest.java"))) + "List of expected tag names for Java." + ) + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Data for Javascript tests + +(defvar semantic-utest-Javascript-buffer-contents +" +function fun1(a, b){ + return a; + } + +function fun2(a,b){ //1 + return b; + } +" +) + + +(defvar semantic-utest-Javascript-name-contents + '(("fun1" function + (:arguments + (("a" variable nil + (reparse-symbol FormalParameterList) + (overlay 15 16 "tst.js")) + ("b" variable nil + (reparse-symbol FormalParameterList) + (overlay 18 19 "tst.js")))) + nil (overlay 1 39 "tst.js")) + ("fun2" function + (:arguments + (("a" variable nil + (reparse-symbol FormalParameterList) + (overlay 55 56 "tst.js")) + ("b" variable nil + (reparse-symbol FormalParameterList) + (overlay 57 58 "tst.js")))) + nil (overlay 41 82 "tst.js"))) + + "List of expected tag names for Javascript.") + + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Data for Makefile tests + +(defvar semantic-utest-Makefile-buffer-contents +" +t1: +\techo t1 + +t2:t1 #1 +\techo t2 + + +" +) + + +(defvar semantic-utest-Makefile-name-contents + '(("t1" function nil nil (overlay 1 9 "Makefile")) + ("t2" function + (:arguments + ("t1")) + nil (overlay 18 28 "Makefile"))) + "List of expected tag names for Makefile.") + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Data for Scheme tests + +(defvar semantic-utest-Scheme-buffer-contents + " + (define fun1 2) + + (define fun2 3 ;1 + ) +") + +(defvar semantic-utest-Scheme-name-contents + '(("fun1" variable + (:default-value ("2")) + nil (overlay 3 18 "tst.scm")) + ("fun2" variable + (:default-value ("3")) + nil (overlay 21 55 "tst.scm"))) + ) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Data for Html tests + +(defvar semantic-utest-Html-buffer-contents + " +<html> + <body> + <h1>hello</h1> + </body><!--1--> +</html> +" + ) + +(defvar semantic-utest-Html-name-contents + '(("hello" section + (:members + (("hello" section nil nil (overlay 21 24 "tst.html")))) + nil (overlay 10 15 "tst.html"))) + ) + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Data for PHP tests + +(defvar semantic-utest-PHP-buffer-contents + "<?php + +function fun1(){ + return \"fun1\"; +} + +function fun2($arg1){ + $output = \"argument to fun2: \" . $arg1; + return $output; +} + +class aClass { + public function fun1($a, $b){ + return $a; + } + + public function fun2($a, $b){ + return $b; + } +} +?> " + ) + +(defvar semantic-utest-PHP-name-contents + '(("fun1" function nil + nil (overlay 9 45 "phptest.php")) + ("fun2" function + (:arguments (("$arg1" variable nil (reparse-symbol formal_parameters) (overlay 61 66 "phptest.php")))) + nil + (overlay 47 132 "phptest.php")) + ("aClass" type + (:members (("fun1" function + (:typemodifiers ("public") :arguments + (("$a" variable nil (reparse-symbol formal_parameters) (overlay 174 176 "phptest.php")) + ("$b" variable nil (reparse-symbol formal_parameters) (overlay 178 180 "phptest.php")))) + + nil + (overlay 153 204 "phptest.php")) + + ("fun2" function + (:typemodifiers ("public") :arguments + (("$a" variable nil (reparse-symbol formal_parameters) (overlay 230 232 "phptest.php")) + ("$b" variable nil (reparse-symbol formal_parameters) (overlay 234 236 "phptest.php")) + )) + nil + (overlay 209 260 "phptest.php"))) :type "class") + nil + (overlay 135 262 "phptest.php")) + ) + "Expected results from the PHP Unit test" + ) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Data for Csharp C# tests + +(defvar semantic-utest-Csharp-buffer-contents +" +class someClass { + int fun1(int a, int b) { + return a; } + int fun2(int a, int b) { + return b; } +} +") + +(defvar semantic-utest-Csharp-name-contents + '(("someClass" type + (:members + (("fun1" function + (:arguments + (("a" variable + (:type "int") + (reparse-symbol formal_parameters) + (overlay 30 35 "tst.cs")) + ("b" variable + (:type "int") + (reparse-symbol formal_parameters) + (overlay 37 42 "tst.cs"))) + :type "int") + (reparse-symbol class_member_declaration) + (overlay 21 61 "tst.cs")) + ("fun2" function + (:arguments + (("a" variable + (:type "int") + (reparse-symbol formal_parameters) + (overlay 73 78 "tst.cs")) + ("b" variable + (:type "int") + (reparse-symbol formal_parameters) + (overlay 80 85 "tst.cs"))) + :type "int") + (reparse-symbol class_member_declaration) + (overlay 64 104 "tst.cs"))) + :type "class") + nil (overlay 1 106 "tst.cs"))) + ) + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + + + +(defun semantic-utest-makebuffer (filename contents) + "Create a buffer for FILENAME for use in a unit test. +Pre-fill the buffer with CONTENTS." + (let ((buff (semantic-find-file-noselect filename))) + (set-buffer buff) + (setq buffer-offer-save nil) + (font-lock-mode -1) ;; Font lock has issues in Emacs 23 + (toggle-read-only -1) ;; In case /tmp doesn't exist. + (erase-buffer) + (insert contents) + ;(semantic-fetch-tags) ;JAVE could this go here? + (set-buffer-modified-p nil) + buff + ) + ) + +(defun semantic-utest-C () + "Run semantic's C unit test." + (interactive) + (save-excursion + (let ((buff (semantic-utest-makebuffer semantic-utest-C-filename semantic-utest-C-buffer-contents)) + (buff2 (semantic-utest-makebuffer semantic-utest-C-filename-h semantic-utest-C-h-buffer-contents)) + ) + (semantic-fetch-tags) + (set-buffer buff) + + ;; Turn off a range of modes + (semantic-idle-scheduler-mode -1) + + ;; Turn on some modes + (semantic-highlight-edits-mode 1) + + ;; Update tags, and show it. + (semantic-fetch-tags) + + (switch-to-buffer buff) + (sit-for 0) + + ;; Run the tests. + ;;(message "First parsing test.") + (semantic-utest-verify-names semantic-utest-C-name-contents) + + ;;(message "Invalid tag test.") + (semantic-utest-last-invalid semantic-utest-C-name-contents '("fun2") "/\\*1\\*/" "/* Deleted this line */") + (semantic-utest-verify-names semantic-utest-C-name-contents) + + (set-buffer-modified-p nil) + ;; Clean up + ;; (kill-buffer buff) + ;; (kill-buffer buff2) + )) + (message "All C tests passed.") + ) + + + + +(defun semantic-utest-generic (testname filename contents name-contents names-removed killme insertme) + "Generic unit test according to template. +Should work for languages withouth .h files, python javascript java. +TESTNAME is the name of the test. +FILENAME is the name of the file to create. +CONTENTS is the contents of the file to test. +NAME-CONTENTS is the list of names that should be in the contents. +NAMES-REMOVED is the list of names that gets removed in the removal step. +KILLME is the name of items to be killed. +INSERTME is the text to be inserted after the deletion." + (save-excursion + (let ((buff (semantic-utest-makebuffer filename contents)) + ) + ;; Turn off a range of modes + (semantic-idle-scheduler-mode -1) + + ;; Turn on some modes + (semantic-highlight-edits-mode 1) + + ;; Update tags, and show it. + (semantic-fetch-tags) + (switch-to-buffer buff) + (sit-for 0) + + ;; Run the tests. + ;;(message "First parsing test %s." testname) + (semantic-utest-verify-names name-contents) + + ;;(message "Invalid tag test %s." testname) + (semantic-utest-last-invalid name-contents names-removed killme insertme) + (semantic-utest-verify-names name-contents) + + (set-buffer-modified-p nil) + ;; Clean up + ;; (kill-buffer buff) + )) + (message "All %s tests passed." testname) + ) + +(defun semantic-utest-Python() + (interactive) + (if (fboundp 'python-mode) + (semantic-utest-generic "Python" (semantic-utest-fname "pytest.py") semantic-utest-Python-buffer-contents semantic-utest-Python-name-contents '("fun2") "#1" "#deleted line") + (message "Skilling Python test: NO major mode.")) + ) + + +(defun semantic-utest-Javascript() + (interactive) + (if (fboundp 'javascript-mode) + (semantic-utest-generic "Javascript" (semantic-utest-fname "javascripttest.js") semantic-utest-Javascript-buffer-contents semantic-utest-Javascript-name-contents '("fun2") "//1" "//deleted line") + (message "Skipping JavaScript test: NO major mode.")) + ) + +(defun semantic-utest-Java() + (interactive) + ;; If JDE is installed, it might mess things up depending on the version + ;; that was installed. + (let ((auto-mode-alist '(("\\.java\\'" . java-mode)))) + (semantic-utest-generic "Java" (semantic-utest-fname "JavaTest.java") semantic-utest-Java-buffer-contents semantic-utest-Java-name-contents '("fun2") "//1" "//deleted line") + )) + +(defun semantic-utest-Makefile() + (interactive) + (semantic-utest-generic "Makefile" (semantic-utest-fname "Makefile") semantic-utest-Makefile-buffer-contents semantic-utest-Makefile-name-contents '("fun2") "#1" "#deleted line") + ) + +(defun semantic-utest-Scheme() + (interactive) + (semantic-utest-generic "Scheme" (semantic-utest-fname "tst.scm") semantic-utest-Scheme-buffer-contents semantic-utest-Scheme-name-contents '("fun2") ";1" ";deleted line") + ) + + +(defun semantic-utest-Html() + (interactive) + ;; Disable html-helper auto-fill-in mode. + (let ((html-helper-build-new-buffer nil)) + (semantic-utest-generic "HTML" (semantic-utest-fname "tst.html") semantic-utest-Html-buffer-contents semantic-utest-Html-name-contents '("fun2") "<!--1-->" "<!--deleted line-->") + )) + +(defun semantic-utest-PHP() + (interactive) + (if (fboundp 'php-mode) + (semantic-utest-generic "PHP" (semantic-utest-fname "phptest.php") semantic-utest-PHP-buffer-contents semantic-utest-PHP-name-contents '("fun1") "fun2" "%^@") + (message "Skipping PHP Test. No php-mode loaded.")) + ) + +;look at http://mfgames.com/linux/csharp-mode +(defun semantic-utest-Csharp() ;; hmm i dont even know how to edit a scharp file. need a csharp mode implementation i suppose + (interactive) + (if (fboundp 'csharp-mode) + (semantic-utest-generic "C#" (semantic-utest-fname "csharptest.cs") semantic-utest-Csharp-buffer-contents semantic-utest-Csharp-name-contents '("fun2") "//1" "//deleted line") + (message "Skipping C# test. No csharp-mode loaded.")) + ) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; stubs + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; stuff for Erlang +;;-module(hello). +;-export([hello_world/0]). +; +;hello_world()-> +; io:format("Hello World ~n"). +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;(defun semantic-utest-Erlang() +; (interactive) +; (semantic-utest-generic "Erlang" (semantic-utest-fname "tst.erl") semantic-utest-Erlang-buffer-contents semantic-utest-Erlang-name-contents '("fun2") "//1" "//deleted line") +; ) +; +;;texi is also supported +;(defun semantic-utest-Texi() +; (interactive) +; (semantic-utest-generic "texi" (semantic-utest-fname "tst.texi") semantic-utest-Texi-buffer-contents semantic-utest-Texi-name-contents '("fun2") "//1" "//deleted line") +; ) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +;;;###autoload +(defun semantic-utest-main() + (interactive) + "call all utests" + (cedet-utest-log-start "multi-lang parsing") + (cedet-utest-log " * C tests...") + (semantic-utest-C) + (cedet-utest-log " * Python tests...") + (semantic-utest-Python) + (cedet-utest-log " * Java tests...") + (semantic-utest-Java) + (cedet-utest-log " * Javascript tests...") + (semantic-utest-Javascript) + (cedet-utest-log " * Makefile tests...") + (semantic-utest-Makefile) + (cedet-utest-log " * Scheme tests...") + (semantic-utest-Scheme) + (cedet-utest-log " * Html tests...") + (semantic-utest-Html) + (cedet-utest-log " * PHP tests...") + (semantic-utest-PHP) + (cedet-utest-log " * Csharp tests...") + (semantic-utest-Csharp) + + (cedet-utest-log-shutdown "multi-lang parsing") + ) + +;;; Buffer contents validation +;; +(defun semantic-utest-match-attributes (attr1 attr2 skipnames) + "Compare attribute lists ATTR1 and ATTR2. +Argument SKIPNAMES is a list of names that may be child nodes to skip." + (let ((res t)) + (while (and res attr1 attr2) + + ;; Compare + (setq res + (cond ((and (listp (car attr1)) + (semantic-tag-p (car (car attr1)))) + ;; Compare the list of tags... + (semantic-utest-taglists-equivalent-p + (car attr2) (car attr1) skipnames) + ) + (t + (equal (car attr1) (car attr2))))) + + (if (not res) + (error "TAG INTERNAL DIFF: %S %S" + (car attr1) (car attr2))) + + (setq attr1 (cdr attr1) + attr2 (cdr attr2))) + res)) + +(defun semantic-utest-equivalent-tag-p (tag1 tag2 skipnames) + "Determine if TAG1 and TAG2 are the same. +SKIPNAMES includes lists of possible child nodes that should be missing." + (and (equal (semantic-tag-name tag1) (semantic-tag-name tag2)) + (semantic-tag-of-class-p tag1 (semantic-tag-class tag2)) + (semantic-utest-match-attributes + (semantic-tag-attributes tag1) (semantic-tag-attributes tag2) + skipnames) + )) + +(defun semantic-utest-taglists-equivalent-p (table names skipnames) + "Compare TABLE and NAMES, where skipnames allow list1 to be different. +SKIPNAMES is a list of names that should be skipped in the NAMES list." + (let ((SN skipnames)) + (while SN + (setq names (remove (car SN) names)) + (setq SN (cdr SN)))) + (while (and names table) + (if (not (semantic-utest-equivalent-tag-p (car names) + (car table) + skipnames)) + (error "Expected %s, found %s" + (semantic-format-tag-prototype (car names)) + (semantic-format-tag-prototype (car table)))) + (setq names (cdr names) + table (cdr table))) + (when names (error "Items forgotten: %S" + (mapcar 'semantic-tag-name names) + )) + (when table (error "Items extra: %S" + (mapcar 'semantic-tag-name table))) + t) + +(defun semantic-utest-verify-names (name-contents &optional skipnames) + "Verify the names of the test buffer from NAME-CONTENTS. +Argument SKIPNAMES is a list of names that should be skipped +when analyzing the file. + +JAVE this thing would need to be recursive to handle java and csharp" + (let ((names name-contents) + (table (semantic-fetch-tags)) + ) + (semantic-utest-taglists-equivalent-p table names skipnames) + )) + +;;;;;;;;;;;;;;;;;;;;;;;; +; JAVE redefine a new validation function +; is not quite as good as the old one yet +(defun semantic-utest-verify-names-jave (name-contents &optional skipnames) + "JAVE version of `semantic-utest-verify-names'. +NAME-CONTENTS is a sample of the tags buffer to test against. +SKIPNAMES is a list of names to remove from NAME-CONTENTS" + (assert (semantic-utest-verify-names-2 name-contents (semantic-fetch-tags)) + nil "failed test") +) + +(defun semantic-utest-verify-names-2 (l1 l2) + (cond ( (and (consp l1) (equal (car l1) 'overlay)) + (overlayp l2)) + ((not (consp l1)) + (equal l1 l2)) + ((consp l1) + (and (semantic-utest-verify-names-2 (car l1) (car l2)) (semantic-utest-verify-names-2 (cdr l1) (cdr l2)))) + (t (error "internal error")))) + + + + + +;;; Kill indicator line +;; +(defvar semantic-utest-last-kill-text nil + "The text from the last kill.") + +(defvar semantic-utest-last-kill-pos nil + "The position of the last kill.") + +(defun semantic-utest-kill-indicator ( killme insertme) + "Kill the line with KILLME on it and insert INSERTME in its place." + (goto-char (point-min)) +; (re-search-forward (concat "/\\*" indicator "\\*/")); JAVE this isnt generic enough for different lagnuages + (re-search-forward killme) + (beginning-of-line) + (setq semantic-utest-last-kill-pos (point)) + (setq semantic-utest-last-kill-text + (buffer-substring (point) (point-at-eol))) + (delete-region (point) (point-at-eol)) + (insert insertme) + (sit-for 0) +) + +(defun semantic-utest-unkill-indicator () + "Unkill the last indicator." + (goto-char semantic-utest-last-kill-pos) + (delete-region (point) (point-at-eol)) + (insert semantic-utest-last-kill-text) + (sit-for 0) + ) + +;;; EDITING TESTS +;; + +(defun semantic-utest-last-invalid (name-contents names-removed killme insertme) + "Make the last fcn invalid." + (semantic-utest-kill-indicator killme insertme) +; (semantic-utest-verify-names name-contents names-removed); verify its gone ;new validator doesnt handle skipnames yet + (semantic-utest-unkill-indicator);put back killed stuff + ) + + + + +;"#<overlay from \\([0-9]+\\) to \\([0-9]+\\) in \\([^>]*\\)>" +;#<overlay from \([0-9]+\) to \([0-9]+\) in \([^>]*\)> +;(overlay \1 \2 "\3") + + +;; JAVE +;; these are some unit tests for cedet that I got from Eric and modified a bit for: +;; python +;; javascript +;; java +;; I tried to generalize the structure of the tests a bit to make it easier to add languages + +;; Mail from Eric: +;; Many items in the checklist look like: + +;; M-x global-semantic-highlight-edits-mode RET +;; - Edit a file. See the highlight of newly inserted text. +;; - Customize `semantic-edits-verbose-flag' to be non-nil. +;; - Wait for the idle scheduler, it should clean up the edits. +;; - observe messages from incremental parser. Do they relate +;; to the edits? +;; - M-x bovinate RET - verify your changes are reflected. + +;; It's all about watching the behavior. Timers go off, things get +;; cleaned up, you type in new changes, etc. An example I tried to +;; do is below, but covers only 1 language, and not very well at that. +;; I seem to remember seeing a unit test framework going by one of the +;; lists. I'm not sure if that would help. + +;; Another that might be automatable: + +;; M-x semantic-analyze-current-context RET +;; - Do this in different contexts in your language +;; files. Verify that reasonable results are returned +;; such as identification of assignments, function arguments, etc. + +;; Anyway, those are some ideas. Any effort you put it will be helpful! + +;; Thanks +;; Eric + +;; ----------- + + + +;;; 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 @@ +;;; From srecode-fields: + +(require 'srecode/fields) + +(defvar srecode-field-utest-text + "This is a test buffer. + +It is filled with some text." + "Text for tests.") + +(defun srecode-field-utest () + "Test the srecode field manager." + (interactive) + (if (featurep 'xemacs) + (message "There is no XEmacs support for SRecode Fields.") + (srecode-field-utest-impl))) + +(defun srecode-field-utest-impl () + "Implementation of the SRecode field utest." + (save-excursion + (find-file "/tmp/srecode-field-test.txt") + + (erase-buffer) + (goto-char (point-min)) + (insert srecode-field-utest-text) + (set-buffer-modified-p nil) + + ;; Test basic field generation. + (let ((srecode-field-archive nil) + (f nil)) + + (end-of-line) + (forward-word -1) + + (setq f (srecode-field "Test" + :name "TEST" + :start 6 + :end 8)) + + (when (or (not (slot-boundp f 'overlay)) (not (oref f overlay))) + (error "Field test: Overlay info not created for field")) + + (when (and (overlay-p (oref f overlay)) + (not (overlay-get (oref f overlay) 'srecode-init-only))) + (error "Field creation overlay is not tagged w/ init flag")) + + (srecode-overlaid-activate f) + + (when (or (not (overlay-p (oref f overlay))) + (overlay-get (oref f overlay) 'srecode-init-only)) + (error "New field overlay not created during activation")) + + (when (not (= (length srecode-field-archive) 1)) + (error "Field test: Incorrect number of elements in the field archive")) + (when (not (eq f (car srecode-field-archive))) + (error "Field test: Field did not auto-add itself to the field archive")) + + (when (not (overlay-get (oref f overlay) 'keymap)) + (error "Field test: Overlay keymap not set")) + + (when (not (string= "is" (srecode-overlaid-text f))) + (error "Field test: Expected field text 'is', not %s" + (srecode-overlaid-text f))) + + ;; Test deletion. + (srecode-delete f) + + (when (slot-boundp f 'overlay) + (error "Field test: Overlay not deleted after object delete")) + ) + + ;; Test basic region construction. + (let* ((srecode-field-archive nil) + (reg nil) + (fields + (list + (srecode-field "Test1" :name "TEST-1" :start 5 :end 10) + (srecode-field "Test2" :name "TEST-2" :start 15 :end 20) + (srecode-field "Test3" :name "TEST-3" :start 25 :end 30) + + (srecode-field "Test4" :name "TEST-4" :start 35 :end 35)) + )) + + (when (not (= (length srecode-field-archive) 4)) + (error "Region Test: Found %d fields. Expected 4" + (length srecode-field-archive))) + + (setq reg (srecode-template-inserted-region "REG" + :start 4 + :end 40)) + + (srecode-overlaid-activate reg) + + ;; Make sure it was cleared. + (when srecode-field-archive + (error "Region Test: Did not clear field archive")) + + ;; Auto-positioning. + (when (not (eq (point) 5)) + (error "Region Test: Did not reposition on first field")) + + ;; Active region + (when (not (eq (srecode-active-template-region) reg)) + (error "Region Test: Active region not set")) + + ;; Various sizes + (mapc (lambda (T) + (if (string= (object-name-string T) "Test4") + (progn + (when (not (srecode-empty-region-p T)) + (error "Field %s is not empty" + (object-name T))) + ) + (when (not (= (srecode-region-size T) 5)) + (error "Calculated size of %s was not 5" + (object-name T))))) + fields) + + ;; Make sure things stay up after a 'command'. + (srecode-field-post-command) + (when (not (eq (srecode-active-template-region) reg)) + (error "Region Test: Active region did not stay up")) + + ;; Test field movement. + (when (not (eq (srecode-overlaid-at-point 'srecode-field) + (nth 0 fields))) + (error "Region Test: Field %s not under point" + (object-name (nth 0 fields)))) + + (srecode-field-next) + + (when (not (eq (srecode-overlaid-at-point 'srecode-field) + (nth 1 fields))) + (error "Region Test: Field %s not under point" + (object-name (nth 1 fields)))) + + (srecode-field-prev) + + (when (not (eq (srecode-overlaid-at-point 'srecode-field) + (nth 0 fields))) + (error "Region Test: Field %s not under point" + (object-name (nth 0 fields)))) + + ;; Move cursor out of the region and have everything cleaned up. + (goto-char 42) + (srecode-field-post-command) + (when (srecode-active-template-region) + (error "Region Test: Active region did not clear on move out")) + + (mapc (lambda (T) + (when (slot-boundp T 'overlay) + (error "Overlay did not clear off of of field %s" + (object-name T)))) + fields) + + ;; End of LET + ) + + ;; Test variable linkage. + (let* ((srecode-field-archive nil) + (f1 (srecode-field "Test1" :name "TEST" :start 6 :end 8)) + (f2 (srecode-field "Test2" :name "TEST" :start 28 :end 30)) + (f3 (srecode-field "Test3" :name "NOTTEST" :start 35 :end 40)) + (reg (srecode-template-inserted-region "REG" :start 4 :end 40)) + ) + (srecode-overlaid-activate reg) + + (when (not (string= (srecode-overlaid-text f1) + (srecode-overlaid-text f2))) + (error "Linkage Test: Init strings are not =")) + (when (string= (srecode-overlaid-text f1) + (srecode-overlaid-text f3)) + (error "Linkage Test: Init string on dissimilar fields is now the same")) + + (goto-char 7) + (insert "a") + + (when (not (string= (srecode-overlaid-text f1) + (srecode-overlaid-text f2))) + (error "Linkage Test: mid-insert strings are not =")) + (when (string= (srecode-overlaid-text f1) + (srecode-overlaid-text f3)) + (error "Linkage Test: mid-insert string on dissimilar fields is now the same")) + + (goto-char 9) + (insert "t") + + (when (not (string= (srecode-overlaid-text f1) "iast")) + (error "Linkage Test: tail-insert failed to captured added char")) + (when (not (string= (srecode-overlaid-text f1) + (srecode-overlaid-text f2))) + (error "Linkage Test: tail-insert strings are not =")) + (when (string= (srecode-overlaid-text f1) + (srecode-overlaid-text f3)) + (error "Linkage Test: tail-insert string on dissimilar fields is now the same")) + + (goto-char 6) + (insert "b") + + (when (not (string= (srecode-overlaid-text f1) "biast")) + (error "Linkage Test: tail-insert failed to captured added char")) + (when (not (string= (srecode-overlaid-text f1) + (srecode-overlaid-text f2))) + (error "Linkage Test: tail-insert strings are not =")) + (when (string= (srecode-overlaid-text f1) + (srecode-overlaid-text f3)) + (error "Linkage Test: tail-insert string on dissimilar fields is now the same")) + + ;; Cleanup + (srecode-delete reg) + ) + + (set-buffer-modified-p nil) + + (message " All field tests passed.") + )) + +;;; From srecode-document: + +(require 'srecode/doc) + +(defun srecode-document-function-comment-extract-test () + "Test old comment extraction. +Dump out the extracted dictionary." + (interactive) + + (srecode-load-tables-for-mode major-mode) + (srecode-load-tables-for-mode major-mode 'document) + + (if (not (srecode-table)) + (error "No template table found for mode %s" major-mode)) + + (let* ((temp (srecode-template-get-table (srecode-table) + "function-comment" + "declaration" + 'document)) + (fcn-in (semantic-current-tag))) + + (if (not temp) + (error "No templates for function comments")) + + ;; Try to figure out the tag we want to use. + (when (or (not fcn-in) + (not (semantic-tag-of-class-p fcn-in 'function))) + (error "No tag of class 'function to insert comment for")) + + (let ((lextok (semantic-documentation-comment-preceeding-tag fcn-in 'lex)) + ) + + (when (not lextok) + (error "No comment to attempt an extraction")) + + (let ((s (semantic-lex-token-start lextok)) + (e (semantic-lex-token-end lextok)) + (extract nil)) + + (pulse-momentary-highlight-region s e) + + ;; Extract text from the existing comment. + (setq extract (srecode-extract temp s e)) + + (with-output-to-temp-buffer "*SRECODE DUMP*" + (princ "EXTRACTED DICTIONARY FOR ") + (princ (semantic-tag-name fcn-in)) + (princ "\n--------------------------------------------\n") + (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 @@ +/* Test scoping rules for c++ in the analyzer. */ + +namespace { + + class aclass2; // Forward reference. + + class aclass1 { + private: + int attrp1; + int amethodp1(int argp1); + aclass2 areference; + protected: + int attrpr1; + public: + int attr1; + int amethod1(int arg1); + }; +} + +namespace { + class aclass2 : public aclass1 + { + private: + int attrp2; + int amethodp2(int argp1); + public: + aclass2(int aninitvalue); + ~aclass2(); + int attr2; + int amethod2(int arg2); + }; +} + +aclass2::aclass2(init aninitvalue) +{ + /* This is a comment that talks about aclass1 */ + aclass1; +} + +int aclass2::amethod2(int arg2) +{ + int alocalvar; + float q; + + ac; +} + 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 @@ +class Foo { + + public void a1() {} + + class Bar { + + public int a2() {} + + public void b() { + a // -1- + } + + class Baz { + + public int a3() {} + + public Baz(int a4) { + a // -2- + } + + } + + } + +}
\ 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 @@ +// C++ examples and requests from Klaus Berndl + +// template in a unnamed namespace +namespace +{ + template<typename Target, typename Source> + Target lexical_cast(Source arg) + { + std::stringstream interpreter; + Target result; + + if(!(interpreter << arg) || !(interpreter >> result) || + !(interpreter >> std::ws).eof()) + throw bad_lexical_cast(); + + return result; + } +} + + +template <class T, FOO> class Vector +{ +private: + static T* v; + int sz; + +public: + T& elem(int i) {return v[i];} + virtual ~Vector (); + +protected: + Vector (); +}; + +template <> class Vector <void*> +{ +private: + void** v; + int sz; + +public: + Vector (); + virtual int func1(int i); + virtual int func2(int i) = 0; + static virtual int func3(int i) = 0; + void*& elem(int i) {return v[i];} + //... +}; + +// template contains namespace +typedef vector<CzkUtilities::Action*> ActionList; + +// declaration of some template-types +map<XXX, Test::YYY>** map_var; + +map_with_size<XXX, Test::YYY, size> map_size_var; +typedef map_with_size<XXX, Test::YYY, size> SizedMap; + +map_with_10_size<XXX, Test::YYY, 10>* pMap_size10_var; +typedef map_with_10_size<XXX, Test::YYY, 10> Size10Map; + +// a function which such a template-argument +void* test_function(map<ClassX, Test::ClassY, 10>* pMap); + + +template <class T> class Vector <T*> : private Vector <void*> +{ +public: + typedef Vector <void*> Base; + + Vector () : Base() {} + + T*& elem(int i) {return static_cast<T*&>(Base::elem(i));} + //... +}; + +// outside method implementation of a template-class +template<class T> T& Vector<T*>::elem(int i) +{ + return C; +} + +// same but qualified with a namespace Testnamespace +template<class T> T& Testnamespace::Vector<T*>::elem(int i) +{ + return C; +} + +// function templates with keyword typename +template<typename Target, typename Source> +Target lexical_cast(Source arg) +{ + std::stringstream interpreter; + Target result; + + if(!(interpreter << arg) || !(interpreter >> result) || + !(interpreter >> std::ws).eof()) + throw bad_lexical_cast(); + + return result; +} + +template<class T> +static +typename T::_ptr_type +getService(const std::string& pServiceName, const int pRetries=20) +{ + return T::_narrow(getServiceObject(pServiceName, pRetries)); +} + +// function template declaration +template<class T> void sort(vector<T>&); +// complex function template definition +template<class T, class S, const NamespaceY::ClassX<TestClass, &s> volatile ***&i> +map<ClassY, ClassX, 10> +sort(const vector<T>& v) +{ + return; +} + +// variable declarations of template-types +foo<TClass, Testnamespace::XClass, i> *bar1; +foo<TClass, Testnamespace::XClass, **&i> *bar2; +foo<TClass, Testnamespace::XClass, *Namespace::ClassX::i> bar3; +foo<0> bar0; + +class SomeName; +class OtherName; + 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 @@ +/* Test file for C language. + * Attempt to include as many aspects of the C language as possible. + * + * $Id: test.c,v 1.1.2.1 2009/09/20 04:00:17 cyd Exp $ + * + */ +/* types of include files */ +#include "includeme1.h" +#include <includeme2.h> +#include <subdir/includeme3.h> +#include <includeme.notanhfile> +#include <stdlib.h> +#include <cmath> + +#if 0 +int dont_show_function() +{ +} +#endif + +/* Global types */ +struct mystruct1 { + int slot11; + char slot12; + float slot13; +}; + +struct mystruct2 { + int slot21; + char slot22; + float slot23; +} var_of_type_mystruct2; + +struct { + int slot31; + char slot32; + float slot33; +} var_of_anonymous_struct; + +typedef struct mystruct1 typedef_of_mystruct1; +typedef struct mystruct1 *typedef_of_pointer_mystruct1; +typedef struct { int slot_a; } typedef_of_anonymous_struct; +typedef struct A { +} B; + +typedef struct mystruct1 td1, td2; + +union myunion1 { + int slot41; + char slot42; + float slot43; +}; + +union myunion2 { + int slot51; + char slot52; + float slot53; +} var_of_type_myunion2; + +struct { + int slot61; + char slot72; + float slot83; +} var_of_anonymous_union; + +typedef union myunion1 typedef_of_myunion1; +typedef union myunion1 *typedef_of_pointer_myunion1; +typedef union { int slot_a; } typedef_of_anonymous_union; + +enum myenum1 { enum11 = 1, enum12 }; +enum myenum2 { enum21, enum22 = 2 } var_of_type_myenum2; +enum { enum31, enum32 } var_of_anonymous_enum; + +typedef enum myenum1 typedef_of_myenum1; +typedef enum myenum1 *typedef_of_pointer_myenum1; +typedef enum { enum_a = 3, enum_b } typedef_of_anonymous_enum; + +typedef int typedef_of_int; + +/* Here are some simpler variable types */ +int var1; +int varbit1:1; +char var2; +float var3; +mystruct1 var3; +struct mystruct1 var4; +union myunion1 var5; +enum myenum1 var6; + +char *varp1; +char **varp2; +char varv1[1]; +char varv2[1][2]; + +char *varpa1 = "moose"; +struct mystruct2 vara2 = { 1, 'a', 0.0 }; +enum myenum1 vara3 = enum11; +int vara4 = (int)0.0; +int vara5 = funcall(); + +int mvar1, mvar2, mvar3; +char *mvarp1, *mvarp2, *mvarp3; +char *mvarpa1 = 'a', *mvarpa2 = 'b', *mvarpa3 = 'c'; +char mvaras1[10], mvaras2[12][13], *mvaras3 = 'd'; + +static register const unsigned int tmvar1; + +#define MACRO1 1 +#define MACRO2(foo) (1+foo) + +/* Here are some function prototypes */ + +/* This is legal, but I decided not to support inferred integer + * types on functions and variables. + */ +fun0(); +int funp1(); +char funp2(int arg11); +float funp3(char arg21, char arg22); +struct mystrct1 funp4(struct mystruct2 arg31, union myunion2 arg32); +enum myenum1 funp5(char *arg41, union myunion1 *arg42); + +char funpp1 __P(char argp1, struct mystruct2 argp2, char *arg4p); + +int fun1(); + +/* Here is a function pointer */ +int (*funcptr)(int a, int b); + +/* Function Definitions */ + +/* This is legal, but I decided not to support inferred integer + * types on functions and variables. + */ +fun0() +{ + int sv = 0; +} + +int fun1 () +{ + int sv = 1; +} + +int fun1p1 (void) +{ + int sv = 1; +} + +char fun2(int arg_11) +{ + char sv = 2; +} + +float fun3(char arg_21, char arg_22) +{ + char sv = 3; +} + +struct mystrct1 fun4(struct mystruct2 arg31, union myunion2 arg32) +{ + sv = 4; +} + +enum myenum1 fun5(char *arg41, union myunion1 *arg42) +{ + sv = 5; +} + +/* Functions with K&R syntax. */ +struct mystrct1 funk1(arg_31, arg_32) + struct mystruct2 arg_31; + union myunion2 arg32; +{ + sv = 4; +} + +enum myenum1 *funk2(arg_41, arg_42) + char *arg_41; + union myunion1 *arg_42; +{ + sv = 5; + + if(foo) { + } +} + +int funk3(arg_51, arg_53) + int arg_51; + char arg_53; +{ + char q = 'a'; + int sv = 6; + td1 ms1; + enum myenum1 testconst; + + /* Function argument analysis */ + funk3(ms1.slot11, arg_53 ); + sv = 7; + + /* Slot deref on assignee */ + ms1.slot11 = s; + + /* Enum/const completion */ + testconst = e; + + /* Bad var/slot and param */ + blah.notafunction(moose); + + /* Print something. */ + printf("Moose", ); + + tan(); +} + +int funk4_fixme(arg_61, arg_62) + int arg_61, arg_62; +{ + +} + +/* 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 @@ +/* Test file for C++ language. + * Attempt to include as many aspects of the C++ language as possible. + * Do not include things tested in test.c since that shares the + * same language. + * + * $Id: test.cpp,v 1.1.2.1 2009/09/20 04:00:17 cyd Exp $ + * + */ + +/* An include test */ +#include <stdio.h> + +#include <cmath> + +#include "c++-test.hh" + +#include <c++-test.hh> + +double var1 = 1.2; + +int simple1(int a) { + +} + +struct foo1 { + int test; +}; + +struct foo2 : public foo1 { + const int foo21(int a, int b); + const int foo22(int a, int b) { return 1 } +}; + +/* Classes */ +class class1 { +private: + int var11; + struct foo1 var12; +public: + int p_var11; + struct foo p_var12; +}; + +class i_class1 : public class1 { +private: + int var11; + struct foo var12; +public: + int p_var11; + struct foo p_var12; +}; + +class class2 { +private: + int var21; + struct foo var22; +public: + int p_var21; + struct foo p_var22; +}; + +class i_class2 : public class1, public class2 { +private: + int var21; + struct foo var22; +protected: + int pt_var21; +public: + int p_var21; + struct foo p_var22; +}; + +class class3 { + /* A class with strange things in it */ +public: + class3(); /* A constructor */ + enum embedded_foo_enum { + a, b, c + } embed1; + struct embedded_bar_struct { + int a; + int b; + } embed2; + class embedded_baz_class { + embedded_baz_class(); + ~embedded_baz_class(); + } embed3; + ~class3(); /* destructor */ + + /* Methods */ + int method_for_class3(int a, char b); + + int inline_method(int c) { return c; } + + /* Operators */ + class3& operator^= (const class3& something); + + /* Funny declmods */ + const class3 * const method_const_ptr_ptr(const int * const argconst) const = 0; +}; + +class3::class3() +{ + /* Constructor outside the definition. */ +} + +int class3::method_for_class3(int a, char b) +{ +} + +int class3::method1_for_class3( int a, int &b) +{ + int cvariablename; + class3 fooy[]; + class3 moose = new class3; + + // Complktion testing line should find external members. + a = fooy[1].me ; + b = cv ; + + if (fooy.emb) { + simple1(c); + } + + cos(10); + abs(10); + + return 1; +} + +char class3::method2_for_class3( int a, int b) throw ( exception1 ) +{ + return 'a'; +} + +void *class3::method3_for_class3( int a, int b) throw ( exception1, exception2 ) +{ + int q = a; + return "Moose"; +} + +void *class3::method31_for_class3( int a, int b) throw ( ) +{ + int q = a; + return "Moose"; +} + +void *class3::method4_for_class3( int a, int b) reentrant +{ + class3 ct; + + ct.method5_for_class3(1,a); + + pritf(); +} + +/* + * A method on class3. + */ +void *class3::method5_for_class3( int a, int b) const +{ +} + +/* + * Namespace parsing tests + */ +namespace NS { + class class_in_namespace { + int equiv(const NS::class_in_namespace *) const; + }; +} + +int NS::class_in_namespace::equiv(const NS::class_in_namespace *cin) const +{ + return 0; +} + +// Stuff Klaus found. +// Inheritance w/out a specifying for public. +class class4 : class1 { + // Pure virtual methods. + void virtual print () const = 0; + +public: + // The whacky constructor type + class4() + try : class1(args) + { + // constructor body + } + catch () + { + + } + + +}; + +class class5 : public virtual class4 { + // Virtual inheritance +}; + +class class6 : class1 { + // Mutable + mutable int i; +}; + +/* Namespaces */ +namespace namespace1 { + void ns_method1() { } + + class n_class1 { + public: + void method11(int a) { } + }; + + /* This shouldn't parse due to missing semicolon. */ + class _n_class2 : public n_class1 { + void n_c2_method1(int a, int b) { } + }; + + // Macros in the namespace +#define NSMACRO 1 + + // Template in the namespace + template<class T> T nsti1(const Foo& foo); + template<> int nsti1<int>(const Foo& foo); + +} + +namespace namespace2 { + + using namespace1::n_class1; + +} + +/* Initializers */ +void tinitializers1(): inita1(False), + inita2(False) +{ + inita1= 1; +} + +/* How about Extern C type things. */ +int funny_prototype(int ,int b,float c) +{ + +} + +extern "C" +int extern_c_1(int a, int b) +{ + + funny_prototype(1,2,3.4); + + printf("Moose", ); + + return 1; +} + +extern "C" { + + int extern_c_2(int a, int b) + { + return 1; + } + +} + +// Some operator stuff +class Action +{ + // Problems!! operator() and operator[] can not be parsed with semantic + // 1.4.2 but with latest c.by + virtual void operator()(int i, char *p ) = 0; + virtual String& operator[]() = 0; + virtual void operator!() = 0; + virtual void operator->() = 0; + virtual T& operator+=(); + virtual T& operator*(); + virtual T& operator*=(); +}; + +// class with namespace qualified parents +class Multiinherit : public virtual POA::Parent, + public virtual POA::Parent1, + Parent +{ +private: + int i; + +public: + Multiinherit(); + ~Multiinherit(); + + // method with a list of qualified exceptions + void* throwtest() + throw(Exception0, + Testnamespace::Exception1, + Testnamespace::Excpetion2, + Testnamespace::testnamespace1::Exception3); + +}; + +void* +Multiinherit::throwtest() + throw (Exception0, + Testnamespace::Exception1, + Testnamespace::Excpetion2, + Testnamespace::testnamespace1::Exception3) +{ + return; +} + +// Jens Rock <jens.rock@asamnet.de>: Nested classes or structs defined +// outside of the containing class/struct. +class container +{ + public: + struct contained; + container(); + ~container(); +}; + +struct container::contained +{ + public: + contained(); + ~contained(); +}; + +/* + * Ok, how about some template stuff. + */ +template <class CT, class container = vector<CT> > +const CT& max (const CT& a, const CT& b) +{ + return a < b ? b : a; +} + +// Arne Schmitz found this one +std::vector<int> &a, &b, &c; + +class TemplateUsingClass +{ + typedef TestClassMap::iterator iterator; + typedef map<long, long> TestClassMap; + + // typedefs with const and volatile + typedef const map<long, long> const_TestClassMap; + typedef TestClassMap<string>::iterator volatile volatile_iterator; + + map<int, int> mapclassvarthingy; +}; + +template<class T> T ti1(const Foo& foo); +template<> int ti1<int>(const Foo& foo); + + +// ----------------------------------- +// Now some namespace and related stuff +// ----------------------------------- + +using CORBA::LEX::get_token; +using Namespace1; + +using namespace POA::std; +using namespace Test; + + + +namespace Parser +{ + namespace + { + using Lexer::get_test; + string str = ""; + } + + namespace XXX + { + + class Foobar : public virtual POA::Parent, + public virtual POA::Parent1, + private POA::list<fact>, + private map<string> + { + ini i; + list <shared_ptr<item> >::const_iterator l; + public: + + Foobar(); + ~Foobar(); + }; + } + + + void test_function(int i); + +}; + +// unnamed namespaces - even nested +namespace +{ + namespace + { + using Lexer::get_test; + string str = ""; + } + + // some builtin types + long long ll = 0; + long double d = 0.0; + unsigned test; + unsigned long int **uli = 0; + signed si = 0; + signed short ss = 0; + short int i = 0; + long int li = 0; + + // expressions with namespace/class-qualifyiers + ORB_var cGlobalOrb = ORB::_nil(); + ORB_var1 cGlobalOrb1 = ORB::_test; + + class Testclass + { + #define TEST 0 + ini i; + + public: + + Testclass(); + ~Testclass(); + }; + + static void test_function(unsigned int i); + +}; + + +// outside method implementations which should be grouped to type Test +XXX& +Test::waiting() +{ + return; +} + +void +Test::print() +{ + return; +} + +// outside method implementations with namespaces which should be grouped to +// their complete (incl. namespace) types +void* +Parser::XXX::Foobar::wait(int i, const char const * const * p) +{ + return; +} + +void* +Namespace1::Test::wait1(int i) +{ + return; +} + +int +Namespace1::Test::waiting(int i) +{ + return; +} + +// a class with some outside implementations which should all be grouped to +// this class declaration +class ClassWithExternals +{ +private: + int i; + +public: + ClassWithExternals(); + ~ClassWithExternals(); + void non_nil(); +}; + + +// Foobar is not displayed; seems that semantic tries to add this to the class +// Foobar but can not find/display it, because contained in the namespace above. +void +Foobar::non_nil() +{ + return; +} + +// are correctly grouped to the ClassWithExternals class +void +ClassWithExternals::non_nil() +{ + String s = "lödfjg dlfgkdlfkgjdl"; + return; +} + +ClassWithExternals::ClassWithExternals() +{ + return; +} + +void +ClassWithExternals::~ClassWithExternals() +{ + return; +} + + +// ------------------------------- +// Now some macro and define stuff +// ------------------------------- + +#define TEST 0 +#define TEST1 "String" + +// The first backslash makes this macro unmatched syntax with semantic 1.4.2! +// With flexing \+newline as nothing all is working fine! +#define MZK_ENTER(METHOD) \ +{ \ + CzkMethodLog lMethodLog(METHOD,"Framework");\ +} + +#define ZK_ASSERTM(METHOD,ASSERTION,MESSAGE) \ + { if(!(ASSERTION))\ + {\ + std::ostringstream lMesgStream; \ + lMesgStream << "Assertion failed: " \ + << MESSAGE; \ + CzkLogManager::doLog(CzkLogManager::FATAL,"",METHOD, \ + "Assert",lMesgStream); \ + assert(ASSERTION);\ + }\ + } + +// Test if not newline-backslashes are handled correctly +string s = "My \"quoted\" string"; + +// parsed fine as macro +#define FOO (arg) method(arg, "foo"); + +// With semantic 1.4.2 this parsed as macro BAR *and* function method. +// With latest c.bnf at least one-liner macros can be parsed correctly. +#define BAR (arg) CzkMessageLog method(arg, "bar"); + +// some const and volatile stuff +char * p1 = "Hello"; // 1. variable Pointer, variable Data +const char * p2 = "Hello"; // 2. variable pointer, constant data +char * const p3 = "Hello"; // 3. constant pointer, variable data +const char * const p4 = "Hello"; // 4. constant pointer, constant data + +// Case 2 and 4 can exchange first "const" and "char" +char const * p21 = "Hello"; // variable pointer, constant data +char const * const p41 = "Hello"; // constant pointer, constant data + +char volatile a = 0; // a volatile char +void foo(bar const &arg); // a reference to a const bar +int foobar(bar const * const p); // a const pointer to a const bar +int foobar(bar const volatile * const p); // a const pointer to a const bar +int foobar3(char* p); // a const pointer to a const bar + +// Should not be parsed because this is invalid code +int const & const r3 = i; + +boolean i = 0; +boolean & r1 = i; +boolean const & r2 = i; + +// const * sequences can be very long in C++ ;-) +char const * const * const * const * ppp; + +// complex function declarationen with named pointer-arguments +const char** foobar1(volatile char const * const **p); +const char** foobar11(volatile Test::Namespace::Char<char*> const * const **p); + +// complex function declarationen with unnamed pointer-arguments +const char* foobar2(const char***); +const char* foobar21(const Test::Namespace::Char<char>***); + +// string literal parsing even with wchar_t +char const *p = "string1"; +char const *q = "string1" "str\"ing2" "string3"; +wchar_t testc = L'a'; + +wchar_t const *wp = L"string with a \" in it"; +wchar_t const *wq = L"string \n\t\"test" L"string2"; +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 @@ +;; Test file for Emacs Lisp. +;; Attempt to include as many aspects of Emacs Lisp as possible. +;; + +;;; Require +;; +(require 'semantic) +(require 'eieio "../eieio") + +;; tags encapsulated in eval-when-compile and eval-and-compile +;; should be expanded out into the outer environment. +(eval-when-compile + (require 'semantic-imenu) + ) + +(eval-and-compile + (defconst const-1 nil) + (defun function-1 (arg) + nil) + ) + +;;; Functions +;; +(defun a-defun (arg1 arg2 &optional arg3) + "doc a" + nil) + +(defun a-defun-interactive (arg1 arg2 &optional arg3) + "doc a that is a command" + (interactive "R") + nil) + +(defun* a-defun* (arg1 arg2 &optional arg3) + "doc a*" + nil) + +(defsubst a-defsubst (arg1 arg2 &optional arg3) + "doc a-subst" + nil) + +(defmacro a-defmacro (arg1 arg2 &optional arg3) + "doc a-macro" + nil) + +(define-overload a-overload (arg) + "doc a-overload" + nil) + +;;; Methods +;; +(defmethod a-method ((obj some-class) &optional arg2) + "Doc String for a method." + (call-next-method)) + +(defgeneric a-generic (arg1 arg2) + "General description of a-generic.") + +;;; Advice +;; +(defadvice existing-function-to-advise (around test activate) + "Do something special to this fcn." + (ad-do-it)) + +;;; Variables +;; +(defvar a-defvar (cons 1 2) + "Variable a") + +(defvar a-defvar-star (cons 1 2) + "*User visible var a") + +(defconst a-defconst 'a "var doc const") + +(defcustom a-defcustom nil + "*doc custom" + :group 'a-defgroup + :type 'boolean) + +(defface a-defface 'bold + "A face that is bold.") + +(defimage ezimage-page-minus + ((:type xpm :file "page-minus.xpm" :ascent center)) + "Image used for open files with stuff in them.") + +;;; Autoloads +;; +(autoload (quote a-autoload) "somefile" + "Non-interactive autoload." nil nil) + +(autoload (quote a-autoload-interactive) "somefile" +"Interactive autoload." t nil) + + +(defgroup a-defgroup nil + "Group for `emacs-lisp' regression-test") + +;;; Classes +;; +(defclass a-class (a-parent) + ((slot-1) + (slot-2 :initarg :slot-2) + (slot-3 :documentation "Doc about slot3") + (slot-4 :type 'boolean) + ) + "Doc String for class.") + +(defclass a-class-abstract () + nil + "Doc string for abstract class." + :abstract t) + +;;; Structures +;; +(defstruct (test-struct-1 :test 'equal) + (slot-1 :equal 'eq) + slot-2) + +(defstruct test-struct-2 + slot-1 + slot-2) + +;;; Semantic specific macros +;; +(define-lex a-lexer + "Doc String" + this + that) + +(define-mode-local-override a-overriden-function + emacs-lisp-mode (tag) + "A function that is overloaded." + nil) + +(defvar-mode-local emacs-lisp-mode a-mode-local-def + "some value") + + +;;; Provide +;; +(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 @@ +# Test makefile -*- makefile -*- + +top= +ede_FILES=Project.ede Makefile + +example_MISC=semantic-skel.el skeleton.bnf +init_LISP=semantic-load.el +DISTDIR=$(top)semantic-$(VERSION) + +# really goofy & variables tabs +A= B +A =B +A=B C +A=B\ + C + +A= http://${B} \ + ftp://${B} +B= test + +all: example semantic Languages tools senator semantic.info + +test ${B}: foo bar + @echo ${A} + +example: + @ + +init: $(init_LISP) + @echo "(add-to-list 'load-path nil)" > $@-compile-script + @if test ! -z "${LOADPATH}" ; then\ + for loadpath in ${LOADPATH}; do \ + echo "(add-to-list 'load-path \"$$loadpath\")" >> $@-compile-script; \ + done;\ + fi + @echo "(setq debug-on-error t)" >> $@-compile-script + $(EMACS) -batch -l $@-compile-script -f batch-byte-compile $^ + +include tesset.mk tusset.mk +include oneset.mk + +ifdef SOME_SYMBOL + VAR1 = foo +else + VAR1 = bar +endif + +ifndef SOME_OTHER_SYMBOL + VAR1 = baz +endif + +ifeq ($(VAR1), foo) + VAR2 = gleep +else + ifneq ($(VAR1), foo) + VAR2 = glop + endif +endif + +# 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 @@ +# Test file for Python language. +# +# $Id: test.py,v 1.1.2.1 2009/09/20 04:00:17 cyd Exp $ + +# Simle class compount statement with blank lines sprinkled. +class Foo(Bar): + + x = 1 + + y = 2 + +# Simple def statement with no argument +def sss(): + i = 1 + +# Simple def statement with arguments +def ttt(x,y,z): + i = 1 + +import foo + +for x in y: + print x + +while y > 0: + y = y - 1 + +a=b=c=d=e=f=i=j=k=l=m=n=o=p=q=r=s=t=x=y=1 + +if x: + x = 2 + y = 3 + +x = 2 +y = 3 +s and t +q | r +o ^ p +m & n +k << l +z = 4 +i >> j +e / f +c * d +a + b +2 ** 5 +x +s = "a" "b" "c" +1 + +# implicit continuation lines, see +# http://docs.python.org/ref/implicit-joining.html + +a_list = [ 1, 2, 3, + 4, 5, + 6 ] + +a_tuple = (1, 2, 3, + + 4, 5, 6) + +a_hash = { 'a':1, "b":2, + 'c' : 3, + "d" : 4 } + + +def longarglist(a, + b, + c, + d): + a=1; + b=1; + c=1; + d=1; + +class longclasslist(xx.yyy, + zz.aa): + foo=1 + + +# wisent-python.wy chokes on this! -ryk 6/17/02 + +class HTTPServer(xxx.yyy): + allow_reuse_address = 1 # Seems to make sense in testing environment + def server_bind(self): + SocketServer.TCPServer.server_bind(self) + host, port = self.socket.getsockname() + self.server_name = socket.getfqdn(host) + self.server_port = port + + +######################################################################### +### /usr/lib/python2.2/BaseHTTPServer.py +######################################################################### + +"""HTTP server base class. + +Note: the class in this module doesn't implement any HTTP request; see +SimpleHTTPServer for simple implementations of GET, HEAD and POST +(including CGI scripts). + +Contents: + +- BaseHTTPRequestHandler: HTTP request handler base class +- test: test function + +XXX To do: + +- send server version +- log requests even later (to capture byte count) +- log user-agent header and other interesting goodies +- send error log to separate file +- are request names really case sensitive? + +""" + + +# See also: +# +# HTTP Working Group T. Berners-Lee +# INTERNET-DRAFT R. T. Fielding +# <draft-ietf-http-v10-spec-00.txt> H. Frystyk Nielsen +# Expires September 8, 1995 March 8, 1995 +# +# URL: http://www.ics.uci.edu/pub/ietf/http/draft-ietf-http-v10-spec-00.txt + + +# Log files +# --------- +# +# Here's a quote from the NCSA httpd docs about log file format. +# +# | The logfile format is as follows. Each line consists of: +# | +# | host rfc931 authuser [DD/Mon/YYYY:hh:mm:ss] "request" ddd bbbb +# | +# | host: Either the DNS name or the IP number of the remote client +# | rfc931: Any information returned by identd for this person, +# | - otherwise. +# | authuser: If user sent a userid for authentication, the user name, +# | - otherwise. +# | DD: Day +# | Mon: Month (calendar name) +# | YYYY: Year +# | hh: hour (24-hour format, the machine's timezone) +# | mm: minutes +# | ss: seconds +# | request: The first line of the HTTP request as sent by the client. +# | ddd: the status code returned by the server, - if not available. +# | bbbb: the total number of bytes sent, +# | *not including the HTTP/1.0 header*, - if not available +# | +# | You can determine the name of the file accessed through request. +# +# (Actually, the latter is only true if you know the server configuration +# at the time the request was made!) + + +__version__ = "0.2" + +__all__ = ["HTTPServer", "BaseHTTPRequestHandler"] + +import sys +import time +import socket # For gethostbyaddr() +import mimetools +import SocketServer + +# Default error message +DEFAULT_ERROR_MESSAGE = """\ +<head> +<title>Error response</title> +</head> +<body> +<h1>Error response</h1> +<p>Error code %(code)d. +<p>Message: %(message)s. +<p>Error code explanation: %(code)s = %(explain)s. +</body> +""" + + +class HTTPServer(SocketServer.TCPServer): + + allow_reuse_address = 1 # Seems to make sense in testing environment + + def server_bind(self): + """Override server_bind to store the server name.""" + SocketServer.TCPServer.server_bind(self) + host, port = self.socket.getsockname() + self.server_name = socket.getfqdn(host) + self.server_port = port + + +class BaseHTTPRequestHandler(SocketServer.StreamRequestHandler): + + """HTTP request handler base class. + + The following explanation of HTTP serves to guide you through the + code as well as to expose any misunderstandings I may have about + HTTP (so you don't need to read the code to figure out I'm wrong + :-). + + HTTP (HyperText Transfer Protocol) is an extensible protocol on + top of a reliable stream transport (e.g. TCP/IP). The protocol + recognizes three parts to a request: + + 1. One line identifying the request type and path + 2. An optional set of RFC-822-style headers + 3. An optional data part + + The headers and data are separated by a blank line. + + The first line of the request has the form + + <command> <path> <version> + + where <command> is a (case-sensitive) keyword such as GET or POST, + <path> is a string containing path information for the request, + and <version> should be the string "HTTP/1.0". <path> is encoded + using the URL encoding scheme (using %xx to signify the ASCII + character with hex code xx). + + The protocol is vague about whether lines are separated by LF + characters or by CRLF pairs -- for compatibility with the widest + range of clients, both should be accepted. Similarly, whitespace + in the request line should be treated sensibly (allowing multiple + spaces between components and allowing trailing whitespace). + + Similarly, for output, lines ought to be separated by CRLF pairs + but most clients grok LF characters just fine. + + If the first line of the request has the form + + <command> <path> + + (i.e. <version> is left out) then this is assumed to be an HTTP + 0.9 request; this form has no optional headers and data part and + the reply consists of just the data. + + The reply form of the HTTP 1.0 protocol again has three parts: + + 1. One line giving the response code + 2. An optional set of RFC-822-style headers + 3. The data + + Again, the headers and data are separated by a blank line. + + The response code line has the form + + <version> <responsecode> <responsestring> + + where <version> is the protocol version (always "HTTP/1.0"), + <responsecode> is a 3-digit response code indicating success or + failure of the request, and <responsestring> is an optional + human-readable string explaining what the response code means. + + This server parses the request and the headers, and then calls a + function specific to the request type (<command>). Specifically, + a request SPAM will be handled by a method do_SPAM(). If no + such method exists the server sends an error response to the + client. If it exists, it is called with no arguments: + + do_SPAM() + + Note that the request name is case sensitive (i.e. SPAM and spam + are different requests). + + The various request details are stored in instance variables: + + - client_address is the client IP address in the form (host, + port); + + - command, path and version are the broken-down request line; + + - headers is an instance of mimetools.Message (or a derived + class) containing the header information; + + - rfile is a file object open for reading positioned at the + start of the optional input data part; + + - wfile is a file object open for writing. + + IT IS IMPORTANT TO ADHERE TO THE PROTOCOL FOR WRITING! + + The first thing to be written must be the response line. Then + follow 0 or more header lines, then a blank line, and then the + actual data (if any). The meaning of the header lines depends on + the command executed by the server; in most cases, when data is + returned, there should be at least one header line of the form + + Content-type: <type>/<subtype> + + where <type> and <subtype> should be registered MIME types, + e.g. "text/html" or "text/plain". + + """ + + # The Python system version, truncated to its first component. + sys_version = "Python/" + sys.version.split()[0] + + # The server software version. You may want to override this. + # The format is multiple whitespace-separated strings, + # where each string is of the form name[/version]. + server_version = "BaseHTTP/" + __version__ + + def parse_request(self): + """Parse a request (internal). + + The request should be stored in self.raw_request; the results + are in self.command, self.path, self.request_version and + self.headers. + + Return value is 1 for success, 0 for failure; on failure, an + error is sent back. + + """ + self.request_version = version = "HTTP/0.9" # Default + requestline = self.raw_requestline + if requestline[-2:] == '\r\n': + requestline = requestline[:-2] + elif requestline[-1:] == '\n': + requestline = requestline[:-1] + self.requestline = requestline + words = requestline.split() + if len(words) == 3: + [command, path, version] = words + if version[:5] != 'HTTP/': + self.send_error(400, "Bad request version (%s)" % `version`) + return 0 + elif len(words) == 2: + [command, path] = words + if command != 'GET': + self.send_error(400, + "Bad HTTP/0.9 request type (%s)" % `command`) + return 0 + else: + self.send_error(400, "Bad request syntax (%s)" % `requestline`) + return 0 + self.command, self.path, self.request_version = command, path, version + self.headers = self.MessageClass(self.rfile, 0) + return 1 + + def handle(self): + """Handle a single HTTP request. + + You normally don't need to override this method; see the class + __doc__ string for information on how to handle specific HTTP + commands such as GET and POST. + + """ + + self.raw_requestline = self.rfile.readline() + if not self.parse_request(): # An error code has been sent, just exit + return + mname = 'do_' + self.command + if not hasattr(self, mname): + self.send_error(501, "Unsupported method (%s)" % `self.command`) + return + method = getattr(self, mname) + method() + + def send_error(self, code, message=None): + """Send and log an error reply. + + Arguments are the error code, and a detailed message. + The detailed message defaults to the short entry matching the + response code. + + This sends an error response (so it must be called before any + output has been generated), logs the error, and finally sends + a piece of HTML explaining the error to the user. + + """ + + try: + short, long = self.responses[code] + except KeyError: + short, long = '???', '???' + if not message: + message = short + explain = long + self.log_error("code %d, message %s", code, message) + self.send_response(code, message) + self.send_header("Content-Type", "text/html") + self.end_headers() + self.wfile.write(self.error_message_format % + {'code': code, + 'message': message, + 'explain': explain}) + + error_message_format = DEFAULT_ERROR_MESSAGE + + def send_response(self, code, message=None): + """Send the response header and log the response code. + + Also send two standard headers with the server software + version and the current date. + + """ + self.log_request(code) + if message is None: + if self.responses.has_key(code): + message = self.responses[code][0] + else: + message = '' + if self.request_version != 'HTTP/0.9': + self.wfile.write("%s %s %s\r\n" % + (self.protocol_version, str(code), message)) + self.send_header('Server', self.version_string()) + self.send_header('Date', self.date_time_string()) + + def send_header(self, keyword, value): + """Send a MIME header.""" + if self.request_version != 'HTTP/0.9': + self.wfile.write("%s: %s\r\n" % (keyword, value)) + + def end_headers(self): + """Send the blank line ending the MIME headers.""" + if self.request_version != 'HTTP/0.9': + self.wfile.write("\r\n") + + def log_request(self, code='-', size='-'): + """Log an accepted request. + + This is called by send_reponse(). + + """ + + self.log_message('"%s" %s %s', + self.requestline, str(code), str(size)) + + def log_error(self, *args): + """Log an error. + + This is called when a request cannot be fulfilled. By + default it passes the message on to log_message(). + + Arguments are the same as for log_message(). + + XXX This should go to the separate error log. + + """ + + apply(self.log_message, args) + + def log_message(self, format, *args): + """Log an arbitrary message. + + This is used by all other logging functions. Override + it if you have specific logging wishes. + + The first argument, FORMAT, is a format string for the + message to be logged. If the format string contains + any % escapes requiring parameters, they should be + specified as subsequent arguments (it's just like + printf!). + + The client host and current date/time are prefixed to + every message. + + """ + + sys.stderr.write("%s - - [%s] %s\n" % + (self.address_string(), + self.log_date_time_string(), + format%args)) + + def version_string(self): + """Return the server software version string.""" + return self.server_version + ' ' + self.sys_version + + def date_time_string(self): + """Return the current date and time formatted for a message header.""" + now = time.time() + year, month, day, hh, mm, ss, wd, y, z = time.gmtime(now) + s = "%s, %02d %3s %4d %02d:%02d:%02d GMT" % ( + self.weekdayname[wd], + day, self.monthname[month], year, + hh, mm, ss) + return s + + def log_date_time_string(self): + """Return the current time formatted for logging.""" + now = time.time() + year, month, day, hh, mm, ss, x, y, z = time.localtime(now) + s = "%02d/%3s/%04d %02d:%02d:%02d" % ( + day, self.monthname[month], year, hh, mm, ss) + return s + + weekdayname = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] + + monthname = [None, + 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', + 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] + + def address_string(self): + """Return the client address formatted for logging. + + This version looks up the full hostname using gethostbyaddr(), + and tries to find a name that contains at least one dot. + + """ + + host, port = self.client_address + return socket.getfqdn(host) + + # Essentially static class variables + + # The version of the HTTP protocol we support. + # Don't override unless you know what you're doing (hint: incoming + # requests are required to have exactly this version string). + protocol_version = "HTTP/1.0" + + # The Message-like class used to parse headers + MessageClass = mimetools.Message + + # Table mapping response codes to messages; entries have the + # form {code: (shortmessage, longmessage)}. + # See http://www.w3.org/hypertext/WWW/Protocols/HTTP/HTRESP.html + responses = { + 200: ('OK', 'Request fulfilled, document follows'), + 201: ('Created', 'Document created, URL follows'), + 202: ('Accepted', + 'Request accepted, processing continues off-line'), + 203: ('Partial information', 'Request fulfilled from cache'), + 204: ('No response', 'Request fulfilled, nothing follows'), + + 301: ('Moved', 'Object moved permanently -- see URI list'), + 302: ('Found', 'Object moved temporarily -- see URI list'), + 303: ('Method', 'Object moved -- see Method and URL list'), + 304: ('Not modified', + 'Document has not changed singe given time'), + + 400: ('Bad request', + 'Bad request syntax or unsupported method'), + 401: ('Unauthorized', + 'No permission -- see authorization schemes'), + 402: ('Payment required', + 'No payment -- see charging schemes'), + 403: ('Forbidden', + 'Request forbidden -- authorization will not help'), + 404: ('Not found', 'Nothing matches the given URI'), + + 500: ('Internal error', 'Server got itself in trouble'), + 501: ('Not implemented', + 'Server does not support this operation'), + 502: ('Service temporarily overloaded', + 'The server cannot process the request due to a high load'), + 503: ('Gateway timeout', + 'The gateway server did not receive a timely response'), + + } + + +def test(HandlerClass = BaseHTTPRequestHandler, + ServerClass = HTTPServer): + """Test the HTTP request handler class. + + This runs an HTTP server on port 8000 (or the first command line + argument). + + """ + + if sys.argv[1:]: + port = int(sys.argv[1]) + else: + port = 8000 + server_address = ('', port) + + httpd = ServerClass(server_address, HandlerClass) + + sa = httpd.socket.getsockname() + print "Serving HTTP on", sa[0], "port", sa[1], "..." + httpd.serve_forever() + + +if __name__ == '__main__': + 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 @@ +// +// CPP file for semantic-ia-utest +// completion engine unit tests. +// +#include "testdoublens.hpp" + +namespace Name1 { + namespace Name2 { + + Foo::Foo() + { + p// -1- + // #1# ( "pMumble" "publishStuff" ) + ; + } + + int Foo::get() // ^1^ + { + p// -2- + // #2# ( "pMumble" "publishStuff" ) + ; + return 0; + } + + void Foo::publishStuff(int /* a */, int /* b */) // ^2^ + { + } + + void Foo::sendStuff(int /* a */, int /* b */) // ^3^ + { + } + + } // namespace Name2 +} // namespace Name1 + +// Test multiple levels of metatype expansion +int test_fcn () { + stage3_Foo MyFoo; + + MyFoo.// -3- + // #3# ( "Mumble" "get" ) + ; + + Name1::Name2::F//-4- + // #4# ( "Foo" ) + ; + + // @TODO - get this working... + Name1::stage2_Foo::M//-5- + /// #5# ( "Mumble" ) + ; +} + +stage3_Foo foo_fcn() { + // Can we go "up" to foo with senator-go-to-up-reference? +} + + +// Second test from Ravikiran Rajagopal + +namespace A { + class foo { + public: + void aa(); + void bb(); + }; +} +namespace A { + class bar { + public: + void xx(); + public: + foo myFoo; + }; + + void bar::xx() + { + myFoo.// -6- <--- cursor is here after the dot + // #6# ( "aa" "bb" ) + ; + } +} + +// Double namespace example from Hannu Koivisto +// +// This is tricky because the parent class "Foo" is found within the +// scope of B, so the scope calculation needs to put that together +// before searching for parents in scope. +namespace a { + namespace b { + + class Bar : public Foo + { + int baz(); + }; + + int Bar::baz() + { + return dum// -7- + // #7# ( "dumdum" ) + ; + } + + } // namespace b +} // namespace a + +// Three namespace example from Hannu Koivisto +// +// This one is special in that the name e::Foo, where "e" is in +// the scope, and not referenced from the global namespace. This +// wasn't previously handled, so the fullscope needed to be added +// to the list of things searched when in split-name decent search mode +// for scopes. + +namespace d { + namespace e { + + class Foo + { + public: + int write(); + }; + + } // namespace d +} // namespace e + + +namespace d { + namespace f { + + class Bar + { + public: + int baz(); + + private: + e::Foo &foo; + }; + + int Bar::baz() + { + return foo.w// -8- + // #8# ( "write" ) + ; + } + + } // namespace f +} // 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 @@ +// +// Header file used in one of the ia-utest tests. +// +namespace Name1 { + namespace Name2 { + + class Foo + { + typedef unsigned int Mumble; + public: + Foo(); + ~Foo(); + int get(); + + private: + void publishStuff(int a, int b); + + void sendStuff(int a, int b); + + Mumble* pMumble; + }; + + typedef Foo stage1_Foo; + + } // namespace Name2 + + typedef Name2::stage1_Foo stage2_Foo; + + typedef Name2::Foo decl_stage1_Foo; + +} // namespace Name1 + +typedef Name1::stage2_Foo stage3_Foo; + + +// Double namespace from Hannu Koivisto +namespace a { + namespace b { + + class Foo + { + struct Dum { + int diDum; + }; + + protected: + mutable a::b::Foo::Dum dumdum; + }; + + } // namespace b +} // 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 @@ +// Test parsing of friends and how they are used in completion. +/* + >> Thanks Damien Profeta for the nice example. + > + > I paste a small example. + > It would be great if friend can be well parsed and even greater if + > class B can access to all the members of A. +*/ + +class Af // %2% ( ( "testfriends.cpp" ) ( "Af" "B::testB" ) ) +{ +public: + int pubVar; +private: + int privateVar; + + friend class B; + +}; + +class B +{ +public: + int testB(); + int testAB(); + +}; + + +int B::testB() { + Af classA; + classA.//-1- + ; //#1# ( "privateVar" "pubVar" ) +} + +int B::testAB() { // %1% ( ( "testfriends.cpp" ) ( "B" "B::testAB" ) ) +} 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 @@ +/** testjavacomp.java --- + * + * Copyright (C) 2009 Eric M. Ludlam + * + * Author: Eric M. Ludlam <eric@siege-engine.com> + * X-RCS: $Id: testjavacomp.java,v 1.1.2.1 2009/09/20 04:00:18 cyd Exp $ + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +package tests.testjavacomp; + +class secondClass { + private void scFuncOne() { } + public void scFuncOne() { } +} + + +public class testjavacomp { + + private int funcOne() { } + private int funcTwo() { } + private char funcThree() { } + + class nestedClass { + private void ncFuncOne() { } + public void ncFuncOne() { } + } + + public void publicFunc() { + + int i; + + i = fu// -1- + // #1# ( "funcOne" "funcTwo" ) + ; + + fu// -2- + // #2# ( "funcOne" "funcThree" "funcTwo" ) + ; + + secondClass SC; + + SC.//-3- + // #3# ( "scFuncOne" ) + ; + + nestedClass NC; + + // @todo - need to fix this? I don't know if this is legal java. + NC.// - 4- + // #4# ( "ncFuncOne" ) + ; + } + +} // 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 @@ +// Test NSP (Name space parent) +// +// Test dereferencing parents based on local parent scope. +// +// Derived from data David Engster provided. + +namespace nsp { + + class rootclass { + public: + int fromroot() {}; + }; + +} + +namespace nsp { + class childclass : public rootclass { + public: + int fromchild() {}; + }; +} + +void myfcn_not_in_ns (void) { + nsp::childclass test; + + test.// -1- + ; // #1# ( "fromchild" "fromroot" ) +} 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 @@ +/** testpolymorph.cpp --- A sequence of polymorphism examples. + * + * Copyright (C) 2009 Eric M. Ludlam + * + * Author: Eric M. Ludlam <eric@siege-engine.com> + * X-RCS: $Id: testpolymorph.cpp,v 1.1.2.1 2009/09/20 04:00:18 cyd Exp $ + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include <cmath> + +// Test 1 - Functions w/ prototypes +namespace proto { + + int pt_func1(int arg1); + int pt_func1(int arg1) { + return 0; + } + +} + +// Test 2 - Functions w/ different arg lists. +namespace fcn_poly { + + int pm_func(void) { + return 0; + } + int pm_func(int a) { + return a; + } + int pm_func(char a) { + return int(a); + } + int pm_func(double a) { + return int(floor(a)); + } + +} + +// Test 3 - Methods w/ differet arg lists. +class meth_poly { +public: + int pm_meth(void) { + return 0; + } + int pm_meth(int a) { + return a; + } + int pm_meth(char a) { + return int(a); + } + int pm_meth(double a) { + return int(floor(a)); + } + +}; + +// Test 4 - Templates w/ partial specifiers. +namespace template_partial_spec { + template <typename T> class test + { + public: + void doSomething(T t) { }; + }; + + template <typename T> class test<T *> + { + public: + void doSomething(T* t) { }; + }; +} + +// Test 5 - Templates w/ full specicialization which may or may not share +// common functions. +namespace template_full_spec { + template <typename T> class test + { + public: + void doSomething(T t) { }; + void doSomethingElse(T t) { }; + }; + + template <> class test<int> + { + public: + void doSomethingElse(int t) { }; + void doSomethingCompletelyDifferent(int t) { }; + }; +} + +// Test 6 - Dto., but for templates with multiple parameters. +namespace template_multiple_spec { + template <typename T1, typename T2> class test + { + public: + void doSomething(T1 t) { }; + void doSomethingElse(T2 t) { }; + }; + + template <typename T2> class test<int, T2> + { + public: + void doSomething(int t) { }; + void doSomethingElse(T2 t) { }; + }; + + template <> class test<float, int> + { + public: + void doSomething(float t) { }; + void doSomethingElse(int t) { }; + void doNothing(void) { }; + }; +} + + +// 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 @@ +/* Attempt to test the C preprocessor + * + */ + +int some_fcn (){} + + +#ifndef MOOSE +int pre_show_moose(){} +#endif + +#ifdef MOOSE +int pre_dont_show_moose(){} +#endif + +#if !defined(MOOSE) +int pre_show_moose_if(){} +#endif + +#if defined(MOOSE) +int pre_dont_show_moose_if(){} +#endif + +#define MOOSE + +#if 0 +int dont_show_function_if_0(){} +#endif + +#if 1 +int show_function_if_1(){} +#endif + +#ifdef MOOSE +int moose_function(){} +#endif + +#ifndef MOOSE +int dont_show_moose(){} +#endif + +#if defined(MOOSE) +int moose_function_if(){} +#endif + +#if !defined(MOOSE) +int dont_show_moose_if() {} +#endif + +#undef MOOSE + +#ifdef MOOSE +int no_handy_moose(){} +#endif + +#ifndef MOOSE +int show_moose_else() {} +#else +int no_show_moose_else(){} +#endif + + +#ifdef MOOSE +int no_show_moose_else_2() {} +#else +int show_moose_else_2() {} +#endif + +#if defined(MOOSE) +int no_show_moose_elif() {} +#elif !defined(MOOSE) +int show_moose_elif() {} +#else +int no_show_moose_elif_else() {} +#endif + +#if defined(MOOSE) +int no_show_moose_if_elif_2() {} +#elif defined(COW) +int no_show_moose_elif_2() {} +#else +int show_moose_elif_else() {} +#endif + 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 @@ +/* Example provided by Hannes Janetzek */ + +struct Test { int test; }; + +#define BLA(_type) \ + _type *bla = (_type*) malloc(sizeof(_type)); + +#define BLUB(_type) \ + (_type*)malloc(sizeof(_type)); + +#define FOO(_type) \ + _type *foo = BLUB(_type); + +#define BAR(_type) \ + _type *bar = (*_type)BLUB(_type); + +int main(int argc, char *argv[]) { + BLA(Test); + bla->// -1- + ; // #1# ( "test" ) + + FOO(Test); + foo->// -2- + ; // #2# ( "test" ) + + BAR(Test); + bar->// -3- + ; // #3# ( "test" ) +} 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 @@ +/* Test CPP/SPP Replacement + */ + +/* TEST: The EMU keyword doesn't screw up the function defn. */ +#define EMU +#define EMU2 /*comment*/ +char EMU parse_around_emu EMU2 (EMU) +{ +} + +/* TEST: A simple word can be replaced in a definition. */ +#define SUBFLOAT /* Some Float */ float +SUBFLOAT returnanfloat() +{ +} + +/* TEST: Punctuation an be replaced in a definition. */ +#define COLON : +int foo COLON COLON bar () +{ +} + +/* TEST: Multiple lexical characters in a definition */ +#define SUPER mysuper:: +int SUPER baz () +{ +} + +/* TEST: Macro replacement. */ +#define INT_FCN(name) int name (int in) + +INT_FCN(increment) { + return in+1; +} + +/* TEST: Macro replacement with complex args */ +#define P_(proto) () + +int myFcn1 P_((a,b)); + +#define P__(proto) proto + +int myFcn2 P__((int a, int b)); +int myFcn3 (int a, int b); + +/* TEST: Multiple args to a macro. */ +#define MULTI_ARGS(name, field1, field2, field3) struct name { int field1; int field2; int field3; } + +MULTI_ARGS(ma_struct, moose, penguin, emu); + +/* TEST: Macro w/ args, but no body. */ +#define NO_BODY(name) + +NO_BODY(Moose); + +/* TEST: Not a macro with args, but close. */ +#define NOT_WITH_ARGS (moose) + +int not_with_args_fcn NOT_WITH_ARGS +{ +} + +/* TEST: macro w/ continuation. */ +#define WITH_CONT \ + continuation_symbol + +int WITH_CONT () { }; + +/* TEST: macros in a macro - tail processing */ +#define tail_with_args_and_long_name(a) (int a) +#define int_arg tail_with_args_and_long_name + +int tail int_arg(q) {} + +/* TEST: macros used improperly. */ +#define tail_fail tail_with_args_and_long_name(q) + +int tail_fcn tail_fail(q); + +/* TEST: feature of CPP from LSD <lsdsgster@...> */ +#define __gthrw_(name) __gthrw_ ## name + +int __gthrw_(foo) (int arg1) { } + +/* TEST: macros using macros */ +#define macro_foo foo +#define mf_declare int macro_foo + +mf_declare; + +/* TEST: macros with args using macros */ +#define Amacro(A) (int A) +#define mf_Amacro(B) int B Amacro(B) + +mf_Amacro(noodle); + +/* TEST: Double macro using the argument stack. */ +#define MACRO0(name) int that_ ## name(int i); +#define MACRO1(name) int this_ ## name(int i); +#define MACRO2(name) MACRO0(name) MACRO1(name) + +MACRO2(foo) + +/* TEST: The G++ namespace macro hack. Not really part of SPP. */ +_GLIBCXX_BEGIN_NAMESPACE(baz) + + int bazfnc(int b) { } + +_GLIBCXX_END_NAMESPACE; + +_GLIBCXX_BEGIN_NESTED_NAMESPACE(foo,bar) + + int foo_bar_func(int a) { } + +_GLIBCXX_END_NESTED_NAMESPACE; + + +/* TEST: The VC++ macro hack. */ +_STD_BEGIN + + int inside_std_namespace(int a) { } + +_STD_END + +/* TEST: Recursion prevention. CPP doesn't allow even 1 level of recursion. */ +#define STARTMACRO MACROA +#define MACROA MACROB +#define MACROB MACROA + +int STARTMACRO () { + +} + + +/* 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 @@ +/* What the SPP replace file would looklike with MACROS replaced. + */ + +/* TEST: The EMU keyword doesn't screw up the function defn. */ +char parse_around_emu () +{ +} + +/* TEST: A simple word can be replaced in a definition. */ +float returnanfloat() +{ +} + +/* TEST: Punctuation an be replaced in a definition. */ +int foo::bar () +{ +} + +/* TEST: Multiple lexical characters in a definition */ +int mysuper::baz () +{ +} + +/* TEST: Macro replacement. */ +int increment (int in) { + return in+1; +} + +/* TEST: Macro replacement with complex args */ +int myFcn1 (); + +int myFcn2 (int a, int b); +int myFcn3 (int a, int b); + +/* TEST: Multiple args to a macro. */ +struct ma_struct { int moose; int penguin; int emu; }; + +/* TEST: Macro w/ args, but no body. */ + +/* TEST: Not a macro with args, but close. */ +int not_with_args_fcn (moose) +{ +} + +/* TEST: macro w/ continuation. */ +int continuation_symbol () { }; + +/* TEST: macros in a macro - tail processing */ + +int tail (int q) {} + +/* TEST: macros used impropertly. */ + +int tail_fcn(int q); + +/* TEST: feature of CPP from LSD <lsdsgster@...> */ + +int __gthrw_foo (int arg1) { } + +/* TEST: macros using macros */ +int foo; + +/* TEST: macros with args using macros */ +int noodle(int noodle); + +/* TEST: Double macro using the argument stack. */ +int that_foo(int i); +int this_foo(int i); + +/* TEST: The G++ namespace macro hack. Not really part of SPP. */ +namespace baz { + + int bazfnc(int b) { } + +} + +namespace foo { namespace bar { + + int foo_bar_func(int a) { } + + } +} + +/* TEST: The VC++ macro hack. */ +namespace std { + + int inside_std_namespace(int a) { } + +} + +/* TEST: Recursion prevention. CPP doesn't allow even 1 level of recursion. */ +int MACROA () { + +} + + +/* 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 @@ +// Combinations of templates and structure inheritance. +// +// Created by Alex Ott. + +template <typename DerivedT> +struct grammar { +public: + typedef grammar<DerivedT> self_t; + typedef DerivedT const& embed_t; + grammar() {} + ~grammar() { } + void use_parser() const { } + void test1() { } +}; + +struct PDFbool_parser : public grammar<PDFbool_parser> { + PDFbool_parser() {} + template <typename scannerT> struct definition { + typedef typename scannerT::iterator_t iterator_t; + int top; + definition(const PDFbool_parser& /*self*/) { + return ; + } + const int start() const { + return top; + } + }; +}; + +int main(void) { + PDFbool_parser PDFbool_p = PDFbool_parser(); + PDFbool_p.//-1- + ; + // #1# ("definition" "embed_t" "self_t" "test1" "use_parser") +} + +// ---------------------------------------------------------------------- + +template <class Derived> struct Base { +public: + void interface() + { + // ... + static_cast<Derived*>(this)->implementation(); + // ... + } + + static void static_func() + { + // ... + Derived::static_sub_func(); + // ... + } +}; + +struct Derived : Base<Derived> { + void implementation() { } + static void static_sub_func() { } +}; + +int foo () { + Derived d; + d.//-2- + ; + // #2# ("implementation" "interface" "static_func" "static_sub_func") +} 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 @@ +/* Special test file for Semantic Analyzer and complex C++ inheritance. + */ + +//#include <iostream> +#include "testsubclass.hh" + +void animal::moose::setFeet(int numfeet) //^1^ +{ + if (numfeet > 4) { + std::cerr << "Why would a moose have more than 4 feet?" << std::endl; + return; + } + + fFeet = numfeet; +} + +int animal::moose::getFeet() //^2^ +{ + return fFeet; +} + +void animal::moose::doNothing() //^3^ +{ + animal::moose foo(); + + fFeet = N// -15- + ; // #15# ( "NAME1" "NAME2" "NAME3" ) +} + + +void deer::moose::setAntlers(bool have_antlers) //^4^ +{ + fAntlers = have_antlers; +} + +bool deer::moose::getAntlers() //^5^ +// %1% ( ( "testsubclass.cpp" "testsubclass.hh" ) ( "deer::moose::doSomething" "deer::moose::getAntlers" "moose" ) ) +{ + return fAntlers; +} + +bool i_dont_have_symrefs() +// %2% ( ("testsubclass.cpp" ) ("i_dont_have_symrefs")) +{ +} + +void deer::moose::doSomething() //^6^ +{ + // All these functions should be identified by semantic analyzer. + getAntlers(); + setAntlers(true); + + getFeet(); + setFeet(true); + + doNothing(); + + fSomeField = true; + + fIsValid = true; +} + +void deer::alces::setLatin(bool l) { + fLatin = l; +} + +bool deer::alces::getLatin() { + return fLatin; +} + +void deer::alces::doLatinStuff(moose moosein) { + // All these functions should be identified by semantic analyzer. + getFeet(); + setFeet(true); + + getLatin(); + setLatin(true); + + doNothing(); + + deer::moose foo(); + + +} + +moose deer::alces::createMoose() +{ + moose MooseVariableName; + bool tmp; + int itmp; + bool fool; + int fast; + + MooseVariableName = createMoose(); + + doLatinStuff(MooseVariableName); + + tmp = this.f// -1- + // #1# ( "fAlcesBool" "fIsValid" "fLatin" ) + ; + + itmp = this.f// -2- + // #2# ( "fAlcesInt" "fGreek" "fIsProtectedInt" ) + ; + + tmp = f// -3- + // #3# ( "fAlcesBool" "fIsValid" "fLatin" "fool" ) + ; + + itmp = f// -4- + // #4# ( "fAlcesInt" "fGreek" "fIsProtectedInt" "fast" ) + ; + + MooseVariableName = m// -5- + // #5# ( "moose" ) + + return MooseVariableName; +} + +/** Test Scope Changes + * + * This function is rigged to make sure the scope changes to account + * for different locations in local variable parsing. + */ +int someFunction(int mPickle) +{ + moose mMoose = deer::alces::createMoose(); + + if (mPickle == 1) { + + int mOption1 = 2; + + m// -5- + // #5# ( "mMoose" "mOption1" "mPickle" ) + ; + + } else { + + int mOption2 = 2; + + m// -6- + // #6# ( "mMoose" "mOption2" "mPickle" ) + ; + } + +} + +// Thanks Ming-Wei Chang for this next example. + +namespace pub_priv { + + class A{ + private: + void private_a(){} + public: + void public_a(); + }; + + void A::public_a() { + A other_a; + + other_a.p// -7- + // #7# ( "private_a" "public_a" ) + ; + } + + int some_regular_function(){ + A a; + a.p// -8- + // #8# ( "public_a" ) + ; + return 0; + } + +} + + +/** Test Scope w/in a function (non-method) with classes using + * different levels of inheritance. + */ +int otherFunction() +{ + sneaky::antelope Antelope(1); + sneaky::jackalope Jackalope(1); + sneaky::bugalope Bugalope(1); + + Antelope.// -9- + // #9# ( "fAntyPublic" "fQuadPublic" "testAccess") + ; + + Jackalope.// -10- + // #10# ( "fBunnyPublic" "testAccess") + ; + + Jackalope// @1@ 6 + ; + Jackalope; + Jackalope; + Jackalope; + + Bugalope.// -11- + // #11# ( "fBugPublic" "testAccess") + ; + Bugalope// @2@ 3 + ; +} + +/** Test methods within each class for types of access to the baseclass. + */ + +bool sneaky::antelope::testAccess() //^7^ +{ + this.// -12- + // #12# ( "fAntyPrivate" "fAntyProtected" "fAntyPublic" "fQuadProtected" "fQuadPublic" "testAccess" ) + ; +} + +bool sneaky::jackalope::testAccess() //^8^ +{ + this.// -13- + // #13# ( "fBunnyPrivate" "fBunnyProtected" "fBunnyPublic" "fQuadProtected" "fQuadPublic" "testAccess" ) + ; +} + +bool sneaky::bugalope::testAccess() //^9^ +{ + this.// -14- + // #14# ( "fBugPrivate" "fBugProtected" "fBugPublic" "fQuadPublic" "testAccess" ) + ; +} + 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 @@ +/* Special test file for Semantic Analyzer and complex C++ inheritance. + * + * Header file for testsubclass.cpp with class defns but no + * implementations. + */ + +//#include <cmath> +// #include <stdio.h> + +#ifndef TESTSUBCLASS_HH +#define TESTSUBCLASS_HH + +namespace animal { + + class moose { + public: + moose() : fFeet(0), + fIsValid(false) + { } + + virtual void setFeet(int); + int getFeet(); + + void doNothing(); + + enum moose_enum { + NAME1, NAME2, NAME3 }; + + + protected: + + bool fIsValid; + int fIsProtectedInt; + + private: + int fFeet; // Usually 2 or 4. + bool fIsPrivateBool; + + }; // moose + + int two_prototypes(); + int two_prototypes(); + + class quadruped { + public: + quadruped(int a) : fQuadPrivate(a) + { } + + int fQuadPublic; + + protected: + int fQuadProtected; + + private: + int fQuadPrivate; + + }; + +} + + +namespace deer { + + class moose : public animal::moose { + public: + moose() : fAntlers(false) + { } + + void setAntlers(bool); + bool getAntlers(); + + void doSomething(); + + protected: + + bool fSomeField; + + private: + bool fAntlers; + + }; + +} // deer + +// A second namespace of the same name will test the +// namespace merging needed to resolve deer::alces +namespace deer { + + class alces : public animal::moose { + public: + alces(int lat) : fLatin(lat) + { } + + void setLatin(bool); + bool getLatin(); + + void doLatinStuff(moose moosein); // for completion testing + + moose createMoose(); // for completion testing. + + protected: + bool fAlcesBool; + int fAlcesInt; + + private: + bool fLatin; + int fGreek; + }; + +}; + +// A third namespace with classes that does protected and private inheritance. +namespace sneaky { + + class antelope : public animal::quadruped { + + public: + antelope(int a) : animal::quadruped(), + fAntyProtected(a) + {} + + int fAntyPublic; + + bool testAccess(); + + protected: + int fAntyProtected; + + private : + int fAntyPrivate; + + }; + + class jackalope : protected animal::quadruped { + + public: + jackalope(int a) : animal::quadruped(), + fBunny(a) + {} + + int fBunnyPublic; + + bool testAccess(); + + protected: + bool fBunnyProtected; + + private : + bool fBunnyPrivate; + + }; + + // Nothing specified means private. + class bugalope : /* private*/ animal::quadruped { + + public: + bugalope(int a) : animal::quadruped(), + fBug(a) + {} + + int fBugPublic; + + bool testAccess(); + protected: + bool fBugProtected; + + private : + bool fBugPrivate; + + }; + + +}; + +#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 @@ +// Templates Test file: +// Written by 'Raf' + +template <class T, int U, class V> +class read_ref { +public: + const T* read_ref_member_one( T); + const V* read_ref_member_two(); +}; + +namespace NS { + template <class T, int U, class V> + class ref { + public: + read_ref<T,10,V> operator->() { + m_// -1- + ; + // #1# ( "m_datas" ) + } + + private: + T m_datas[U]; + }; + +} + +class FooOne { +public: + int fooOneMember(); +}; + +class FooTwo { +public: + int fooTwoMember(); +}; + +class FooThree { +public: + int fooThreeMember(); + + FooOne * operator->(); +}; + +typedef ref<FooOne, 10,FooTwo> Test; + +using NS; + +void +main(void) { + ref<FooOne, 10, FooTwo> v; + + v->read_ref_member_one()-> // -2- + ; + // #2# ( "fooOneMember" ) + + v->read_ref_member_two()-> // -3- + ; + // #3# ( "fooTwoMember" ) + + v-> // -4- + ; + // #4# ( "read_ref_member_one" "read_ref_member_two" ) + + Test t; + + t->read_ref_member_two()-> // -5- + ; + // #5# ( "fooTwoMember" ) + + ref<FooOne, 10, FooThree> v2; + + v2->read_ref_member_two()-> // -6- + ; + // #6# ( "fooOneMember" ) + + /* Try all these things by also specifying the namespace in the name. */ + NS::ref<FooOne, 10, FooTwo> v3; + + v3->read_ref_member_one()-> // -7- + ; + // #7# ( "fooOneMember" ) + + v3->read_ref_member_two()-> // -8- + ; + // #8# ( "fooTwoMember" ) + + v3->read_ref_member_two// @1@ 5 + ; + +} 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 @@ +// Sample with some fake bits out of std::string +// +// Thanks Ming-Wei Chang for these examples. + +namespace std { + + template <T>class basic_string { + + public: + void resize(int); + + }; + +} + +typedef std::basic_string<char> mstring; + +using namespace std; +typedef basic_string<char> bstring; + + +int main(){ + mstring a; + + a.// -1- + ; + // #1# ( "resize" ) + + bstring b; + // It doesn't work here. + b.// -2- + ; + // #2# ( "resize" ) + + return 0; +} + + +// ------------------ + +class Bar +{ +public: + void someFunc() {} + +}; + +typedef Bar new_Bar; + +template <class mytype> +class TBar +{ +public: + void otherFunc() {} + +}; + +typedef TBar<char> new_TBar; + +int main() +{ + new_Bar nb; + new_TBar ntb; + + nb.// -3- + ; + // #3# ("someFunc") + + ntb.// -4- + ; + // #4# ("otherFunc") + + return 0; +} 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 @@ +// Test using statements in C++ + +#include <adstdio.h> + +#include <testusing.hh> + +namespace moose { + + class MyClass; + class Point; + + typedef MyClass snerk; +} + +namespace moose { + + class Point; + class MyClass; + +} + +namespace { + + int global_variable = 0; + +}; + +using moose::MyClass; + +void someFcn() { + + MyClass f; + + f.//-1- + ; //#1# ( "getVal" "setVal" ) + +} + +// Code from Zhiqiu Kong + +namespace panda { + + using namespace bread_name; + + int func() + { + bread test; + test.//-2- + ;// #2# ( "geta" ) + return 0; + } +} + +// Local using statements and aliased types +// Code from David Engster + +void func2() +{ + using namespace somestuff; + OneClass f; + f.//-3- + ; //#3# ( "aFunc" "anInt" ) +} + +void func3() +{ + using somestuff::OneClass; + OneClass f; + f.//-4- + ; //#4# ( "aFunc" "anInt" ) +} + +// Dereferencing alias types created through 'using' statements + +// Alias with fully qualified name +void func4() +{ + otherstuff::OneClass f; + f. //-5- + ; //#5# ( "aFunc" "anInt" ) +} + +// Alias through namespace directive +void func5() +{ + using namespace otherstuff; + OneClass f; + f. //-6- + ; //#6# ( "aFunc" "anInt" ) +} + +// Check name hiding +void func6() +{ + using namespace morestuff; + OneClass f; // Alias for somestuff::OneClass + f. //-7- + ; //#7# ( "aFunc" "anInt" ) + aStruct g; // This however is morestuff::aStruct ! + g. //-8- + ; //#8# ( "anotherBar" "anotherFoo" ) +} + +// Alias of an alias +// Currently doesn't work interactively for some reason. +void func6() +{ + using namespace evenmorestuff; + OneClass f; + f. //-7- + ; //#7# ( "aFunc" "anInt" ) +} + +// Alias for struct in nested namespace, fully qualified +void func7() +{ + outer::StructNested f; + f.//-8- + ; //#8# ( "one" "two" ) +} + +// Alias for nested namespace +void func8() +{ + using namespace outerinner; + StructNested f; + AnotherStruct g; + f.//-9- + ; //#9# ( "one" "two" ) + g.//-10- + ; //#10# ( "four" "three" ) +} 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 @@ +// test usings header file. + +namespace moose { + + class Point; + + class MyClass; + +} + + +namespace moose { + + class Point; + + class MyClass { + public: + MyClass() : fVal(0) { + } + + ~MyClass() {}; + + /** + * fVal Accessors + * @{ + */ + int getVal() const { + return fVal; + } + void setVal(int Val) const { + fVal = Val; + } + /** + * @} + */ + private: + int fVal; + }; + +} + +namespace deer { + + class Pickle; + +}; + +// Code from Zhiqiu Kong + +#ifndef BREAD_H +#define BREAD_H + +namespace bread_name { + class bread + { + public: + void geta(); + private: + int m_a; + int m_b; + }; +} + +#endif + +// Code from David Engster +// Creating alias types through 'using' trickery + +namespace somestuff { + class OneClass { + public: + void aFunc(); + int anInt; + }; + struct aStruct { + int foo; + int bar; + }; +} + +namespace otherstuff { + // make otherstuff::OneClass an alias for somestuff::OneClass + using somestuff::OneClass; +} + +namespace morestuff { + // make morestuff an alias namespace for somestuff + using namespace somestuff; + // but hide aStruct with own type + struct aStruct { + int anotherFoo; + int anotherBar; + }; +} + +// We can also create an alias for an alias +namespace evenmorestuff { + using otherstuff::OneClass; +} + +// Now with nested namespaces +namespace outer { + namespace inner { + struct StructNested { + int one; + int two; + }; + struct AnotherStruct { + int three; + int four; + }; + } +} + +// Elevate the first struct into 'outer' +// so that we can access it via 'outer::StructNested' +namespace outer { + using outer::inner::StructNested; +} + +// Create an alias for a nested namespace +namespace outerinner { + // equivalent to 'namespace outerinner = outer::inner;' + using namespace outer::inner; +} 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 @@ +/* + * Test variable and function names, lists of variables on one line, etc. + */ + +struct independent { + int indep_1; + int indep_2; +}; + +struct independent var_indep_struct; + +struct { + int unnamed_1; + int unnamed_2; +} var_unamed_struct; + +struct { + int unnamed_3; + int unnamed_4; +} var_un_2, var_un_3; + +struct inlinestruct { + int named_1; + int named_2; +} var_named_struct; + +struct inline2struct { + int named_3; + int named_4; +} var_n_2, var_n_3; + +/* Structures with names that then declare variables + * should also be completable. + * + * Getting this to work is the bugfix in semantic-c.el CVS v 1.122 + */ +struct inlinestruct in_var1; +struct inline2struct in_var2; + +int test_1(int var_arg1) { + + var_// -1- + ; // #1# ("var_arg1" "var_indep_struct" "var_n_2" "var_n_3" "var_named_struct" "var_un_2" "var_un_3" "var_unamed_struct") + + var_indep_struct.// -2- + ; // #2# ( "indep_1" "indep_2" ) + + var_unamed_struct.// -3- + ; // #3# ( "unnamed_1" "unnamed_2" ) + + var_named_struct.// -4- + ; // #4# ( "named_1" "named_2" ) + + var_un_2.// -5- + ; // #5# ( "unnamed_3" "unnamed_4" ) + var_un_3.// -6- + ; // #6# ( "unnamed_3" "unnamed_4" ) + + var_n_2.// -7- + ; // #7# ( "named_3" "named_4" ) + var_n_3.// -8- + ; // #8# ( "named_3" "named_4" ) + + in_// -9- + ; // #9# ( "in_var1" "in_var2" ) + + in_var1.// -10- + ; // #10# ( "named_1" "named_2") + in_var2.// -11- + ; // #11# ( "named_3" "named_4") +} |