id
int64 0
45.1k
| file_name
stringlengths 4
68
| file_path
stringlengths 14
193
| content
stringlengths 32
9.62M
| size
int64 32
9.62M
| language
stringclasses 1
value | extension
stringclasses 6
values | total_lines
int64 1
136k
| avg_line_length
float64 3
903k
| max_line_length
int64 3
4.51M
| alphanum_fraction
float64 0
1
| repo_name
stringclasses 779
values | repo_stars
int64 0
882
| repo_forks
int64 0
108
| repo_open_issues
int64 0
90
| repo_license
stringclasses 8
values | repo_extraction_date
stringclasses 146
values | sha
stringlengths 64
64
| __index_level_0__
int64 0
45.1k
| exdup_ids_cmlisp_stkv2
sequencelengths 1
47
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
24,940 | main.lisp | mparlaktuna_cl-cu2e/main.lisp | (in-package :cl-cu2e)
(defclass shape () ())
(defclass model ()
((pos :initarg :pos :accessor model-pos)
(shape :initarg :shape :accessor model-shape)))
(defclass visual-model (model) ())
(defmethod make-visual-model ((pos vec2) (shape shape))
(make-instance 'visual-model :pos pos :shape shape))
(defclass physical-model (model) ())
(defmethod make-physical-model ((pos vec2) (shape shape))
(make-instance 'physical-model :pos pos :shape shape))
(defclass circle (shape)
((radius :initarg :radius :accessor circle-radius)))
(defun make-circle (rad)
(make-instance 'circle :radius rad))
(defclass object ()
((physical :initarg :physical :accessor object-physical)
(visual :initarg :visual :accessor object-visual)))
(defmethod make-object ((phy physical-model) (vis visual-model))
(make-instance 'object :physical phy :visual vis))
(defclass scene ()
((name :initarg :name :accessor scene-name)
(models :initform nil :accessor scene-models)
(dt :initarg dt :accessor scene-dt)
(thread :initform nil :accessor scene-thread)
(continue-thread :initform nil :accessor continue-thread)
(scene-thread-hook :initform nil)
(dims :initform nil :reader scene-dims)))
(defclass scene2d (scene)
((dims :initform 2)))
(defun make-scene (name dt)
(make-instance 'scene :name name))
(defmethod add-object ((scene scene) (object object))
(push object (scene-models scene)))
(defmethod clear-objects ((scene scene))
(setf (scene-models scene) nil))
(defmethod stop-thread ((scene scene))
(setf (continue-thread scene) nil))
(defmethod start-thread ((scene scene))
(setf (continue-thread scene) T)
(setf (scene-thread scene) (bt:make-thread
(lambda ()
(loop while (continue-thread scene) do
(sleep 2)
(format t "after ~a~%" (continue-thread scene)))))))
| 1,853 | Common Lisp | .lisp | 45 | 37.577778 | 64 | 0.712838 | mparlaktuna/cl-cu2e | 1 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | a23a382d206f4e9d047f9b4d594e97fe8184a63a9fd62fd65a8246c6d738423a | 24,940 | [
-1
] |
24,941 | cl-cu2e-test.lisp | mparlaktuna_cl-cu2e/cl-cu2e-test.lisp | (in-package :cl-user)
(defpackage cl-cu2e-test
(:use :cl
:prove :cl-cu2e 3d-vectors))
(in-package :cl-cu2e-test)
(plan 0)
(finalize)
| 155 | Common Lisp | .lisp | 7 | 18 | 36 | 0.676471 | mparlaktuna/cl-cu2e | 1 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 7c77868bc73085acafadbebe5b868c9ba42f295504aada75449f75e922348662 | 24,941 | [
-1
] |
24,942 | cl-cu2e.asd | mparlaktuna_cl-cu2e/cl-cu2e.asd | (cl:in-package #:asdf-user)
(require :alexandria)
(require :prove)
(require :3d-vectors)
(require :3d-matrices)
(require :mcclim)
(require :cl-hooks)
(require :iterate)
(defsystem :cl-cu2e
:description ""
:version "0.0.1"
:author "Mustafa Parlaktuna <[email protected]>"
:license "GPLv3"
:serial t
:depends-on (:alexandria :3d-vectors :3d-matrices :clim :cl-hooks :iterate)
:in-order-to ((test-op (test-op cl-cu2e-test)))
:components ((:file "package")
(:file "main")
(:file "ui")))
(defsystem cl-cu2e-test
:depends-on (:cl-cu2e
:prove)
:defsystem-depends-on (:prove-asdf)
:components
((:test-file "cl-cu2e-test"))
:perform (test-op :after (op c)
(funcall (intern #.(string :run) :prove) c)))
| 819 | Common Lisp | .asd | 27 | 24.814815 | 77 | 0.64191 | mparlaktuna/cl-cu2e | 1 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 82985afcee469270dd4f473929c8635b483b236ea5014686b93ef395ae0cf5ed | 24,942 | [
-1
] |
24,963 | cl-df-p1.lisp | MetaCommunity_esym/src/main/cltl/cl-df-p1.lisp | ;; cl-df-p1.lisp - a simple data flow programming prototype
#|
Primary reference:
[J2004] Johnston, Wesley JR, Paul Hanna ans Richard Millar. Advances in Dataflow Programming Languages. ACM Comput. Surv. 2004.
|#
(in-package #:cl-user)
(eval-when (:compile-toplevel :load-toplevel :execute)
(defpackage #:df.p1
(:use #:cl))
)
(in-package #:df.p1)
(defclass data-source ()
())
(defclass data-sink ()
())
(defclass constant (data-source)
())
(defgeneric data-available-p (source)
(:method ((source constant))
(values t nl)))
(defclass op ()
()) ;; op impl. may be either or both of data source/sink
(defgeneric run-op (op)) ;; oversimplified?
(defclass pin (data-source data-sink)
())
(defclass op-type ()
())
(defclass monadic-op-type (op-type)
;; op-type for operation providing a single "output pin"
())
(defclass mv-op-type (op-type)
;; op-type for operations providing multiple "ouput pins"
())
(degeneric op-type-input-pins (type))
;; => list of pin
(defgenric op-type-output-pins (type))
;; => list of pin
(defclass wire ()
((input-pin
:initarg :input-pin
:accessor wire-input-pin
:type pin)
(output-pin
:initarg :input-pin
:accessor wire-output-pin
:type pin)))
(defgeneric op-inputs (op))
;; => sequence of wire
(defgeneic op-outputs (op))
;; => sequence of wire
(defclass op-class (standard-class op-type)
())
(defclass monadic-op-class (op-class monadic-op-type)
())
(defclass mv-op-class (op-class mv-op-type)
())
(defclass functional-op-type (op-type)
;; FIXME: In SHARED-INITIALIZE :AROUND (?)
;; ensure NATIVE-FUNCTION is compiled (when possible??)
((native-function
:initarg :native-fuction
:type function
:accessor op-type-nayive-function))
(defclass functional-op-class (op-class functional-op-type)
())
(defclass monadic-functional-op-class (monadic-op-class functional-op-class)
())
(defclass mv-functional-op-class (mv-op-class functional-op-class)
())
(deflass add-op (op data-source data-sink)
()
(:metaclass functional-monadic-op-class))
(defmethod run-op ((op add-op))
;; referencing [J2004], two approaches for implementing a dataflow model:
;;
;; 1. data-driven approach
;; * essentially towards a "top-down" control flow in implementing a data flow graph.
;;
;; 2. demand-driven approach
;; * essentially towards a "bottom-up" control flow.
;;
;; Ostensibly, both approaches may be implemented – towards developing an interactive, functional data flow implementation in Commom Lisp.
;;
;; Use case: Data Flow Program , P, "Simple adder"
;;
;; Given:
;; Node A0, providing constant value "1" on single outout pin A0P0
;; Node A1, providing constant value "2" on single output pin A1P0
;; Node B0, "Addition operation", two input pins (B0R0, B0R1), single output pin (B0P0)
;; Node C0, "Value predentation", one input pin (C0R0), no output pins
;; Wiring:
;; (A0P0, B0R0)
;; (A1P0, B0R1)
;; (B0P0, C0R0)
;;
;; Scenario 1: P evaluated in data-driven evaluation
;;
;; Use case scenario: User requests P evluation
;;
;; Procedural overview:
;;
;; 1. Starting at initial "top" nodes A0, A1, ensure data is available to be read from "print" pins of each node (i.e A0P0, A1P0). Whereas this scenario implements A0, A1 as "Constant value" nodes (contrast: meaurement sampling nodes) data will be constantly available on A0P0, A1P0
;;
;; 2. Availability of data on A0P0, A1P0 => "Evaluate wiring" => Evaluate B0
;;
;; Procedure (abstract) :
;;
;; 1. Access "wire configuration" for A0, A1 output pins
;; * Data is available on A0P0 => Data is available on B0R0 (activate pin B0R0 on node B0, check if all B0 "read" pins are active, evaluate B0 if so)
;;
;; * Data is available on A1P0 => Data is available on B0R1 (activate pin B0R1 on node B0, check if all B0 "read" pins are active, and now that is "true", evaluate B0 )
;;
;; 2. On activation of all "read"" pins on B0, evaluate B0 (functional evaluation).
;;
;; 3. On completion of functional evaluation of B0, store values in B0 "print" pins (B0P0), and activate each "print" pin. After thr resulting data values are stored onto each/all (?) "print" pins, then "cascade the activation signal" onto those "print" pins.
;; (NOTE: CONFIGURATION AND HOST SUPPORT: PARALLEL i.e "multithreaded" (i.e available only in multi-threaded host environments) or SERIAL i.e "single-threaded" (i.e available in every host envirpnment) NODE ACTIVATION CASCADE i.e node signal/evaluation methodlogy - USER-ACCESSIBLE CONFIGURATION OPTION, CONFIGURABLE PER: EACH APPLICATION, EACH PROGRAM, AND EACH NODE. FURTHER CONFIGURATION (PER NODE): NODAL CASCADE SEQUENCE (FOR SERIAL CASCADE))
;;
;; 1. "Evaluate wires" on pin B0P0
;; B0P0 ... C0R0
;; 2. Store data value onto C0R0 (node C0) and activate C0R0
;; 3. Evaluate Node C0 (functional evaluation)
;;
;. 4. Node C0 presents its input data value (e.g using synthesized speech as in an audible event notification model, and/or presenting the data value onto a graphical display screen as in a digital graphical event notification model, or displaying the value onto a single, digital LED readout on a microcontroller, in a modular microcontroller design, and optionally presenting the value for storage in an event-series data logging model, for use in system metrics and reporting. Inspired by U. Edinburgh CSTR's Festival Speech Synthesis System, digital multimeter models with data logging capability, oscilloscope with data logging capability, Arduino, Adafruit, NI PXI, Idaho National Laboratory (social networking), Jasper Reports, and Franchise Tax Board)
;;
;;
;; Scenario 2: P evaluated in demand-driven "sample mode" evaluation beginning at C0
;;
;; Use case scenario: User requests sample of current data value at C0
;;
;; Procedural overview:
;;
;; Starting at node C0:
;; 1. Retrieve list of "read" pins on C0
;; => C0R0
;; 2. Determine the "wire" for each "read" pin, then the respective "peer pin" of wire, then the node containing that "peer pin"
;, B0P0 => (B0P0, C0R0) => C0R0 => C0
;; 3. Determine "node availability" (node C0), i.e Determine, Is Data availabile on all "read" pins in C0? (i.e for each "read" pin on C0, compute "read" pin => wire => print pin => node => availability) until arriving at a set of "available" nodes having no "read" pins.
;; 4. Given set of "initial top nodes", then begin top-down functional evaluation, starting with that set of "initial top nodes" (optionally, towards a "Debug mode" requirement: isolate evaluation to the "call tree" -- i.e data flow graph -- as computed in this instance, as beginning at C0, essentially "disabling" any "print pins" not included in that data flow graph. The "Isolated Debug" call tree for C0, as an object, may be assigned to C0, once computed.)
;;
(to-do ))
(define-condition to-do (program-error)
((annotations :initarg :annotations :reader condition-annotations :initform nil))
(:report (lambda (c s) (format s "To Do~@[~s~]" (condition-annotations c)))))
(defmacro to-do (&rest annotations)
`(evaluate-when (:compile-toplevel)
(error 'to-do :annotations (list ,@annotations))))
| 7,590 | Common Lisp | .lisp | 146 | 47.808219 | 764 | 0.686428 | MetaCommunity/esym | 1 | 0 | 0 | EPL-1.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 67e9e739bb82a8c40efc0737613f3f22fdef2a98187d965650ab6639a51d7bbd | 24,963 | [
-1
] |
24,965 | Digital.sheet | MetaCommunity_esym/src/main/resources/dia/dia_digital/sheets/Digital.sheet | <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<sheet xmlns="http://www.lysator.liu.se/~alla/dia/dia-sheet-ns">
<!--Dia-Version: 0.96.1-->
<!--File: /home/jason/.dia/sheets/Digital.sheet-->
<!--Date: Thu Jul 19 15:30:37 2007-->
<!--For: jason-->
<name>Digital</name>
<description>Digital Logic Gates</description>
<contents>
<object name="Digital - buff_h">
<description>Buffer (horizontal)</description>
</object>
<object name="Digital - inv_h">
<description>Inverter (horizontal)</description>
</object>
<object name="Digital - and_h">
<description>AND (horizontal)</description>
</object>
<object name="Digital - nand_h">
<description>NAND (horizontal)</description>
</object>
<object name="Digital - or_h">
<description>OR (horizontal)</description>
</object>
<object name="Digital - nor_h">
<description>NOR (horizontal)</description>
</object>
<object name="Digital - xor_h">
<description>XOR (horizontal)</description>
</object>
<object name="Digital - xnor_h">
<description>XNOR (horizontal)</description>
</object>
<object name="Digital - mux_h">
<description>Multiplexer/Demultiplexer (horizontal)</description>
</object>
<object name="Digital - add_h">
<description>Adder/Subtractor/Multiplier/Divider (horizontal)</description>
</object>
<object name="Digital - reg_h">
<description>Register (horizontal)</description>
</object>
<br/>
<object name="Digital - buff_v">
<description>Buffer (vertical)</description>
</object>
<object name="Digital - inv_v">
<description>Inverter (vertical)</description>
</object>
<object name="Digital - and_v">
<description>AND (vertical)</description>
</object>
<object name="Digital - nand_v">
<description>NAND (vertical)</description>
</object>
<object name="Digital - or_v">
<description>OR (vertical)</description>
</object>
<object name="Digital - nor_v">
<description>NOR (vertical)</description>
</object>
<object name="Digital - xor_v">
<description>XOR (vertical)</description>
</object>
<object name="Digital - xnor_v">
<description>XNOR (vertical)</description>
</object>
<object name="Digital - mux_v">
<description>Multiplexer/Demultiplexer (vertical)</description>
</object>
<object name="Digital - add_v">
<description>Adder/Subtractor/Multiplier/Divider (vertical)</description>
</object>
<object name="Digital - reg_v">
<description>Register (vertical)</description>
</object>
<br/>
<object name="Digital - conn">
<description>Connection Point</description>
</object>
</contents>
</sheet>
| 2,626 | Common Lisp | .l | 82 | 29.012195 | 78 | 0.698506 | MetaCommunity/esym | 1 | 0 | 0 | EPL-1.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 60a1d0b9d8d53be35bec31f39164de43f65e181cc23d2ed0a72de784c85f8d60 | 24,965 | [
-1
] |
24,981 | super-loader.lisp | jordan4ibanez_super-loader/super-loader.lisp | ;; Thanks to ICan'tThinkOfAGoodName in the Lisp Discord for helping out with making this work on Windows!
(in-package #:super-loader)
(export '(super-load))
(defun super-load(relative-path)
"Loads an asdf system based on the relative path of the current working directory (root of project).
This function is primarily aimed at game dev.
You can use this to load your project specific local systems in a traditional Java/Lua/Python-like manor.
The folder which encapsulates your system must match the name of your system.
The .asd file which identifies your system much match the name of your system.
Arg: relative-path is a list of strings. Pretend each space is walking into a new folder.
Example: (super-load \"game-things/my-cool-system\")
Now system :my-cool-system has been loaded, packages contained inside of it are freely available."
;; Note, Windows systems use "/" for file hierarchy.
(let ((old-relative-path relative-path))
;; This is why you don't have to append "/" to your string!
(setq relative-path (concatenate 'string relative-path "/"))
(handler-case
(let ((system-name (car (last (pathname-directory relative-path))))
(real-path (truename relative-path)))
(let ((asd-file-name (concatenate 'string system-name ".asd")))
(let ((completed-asd-path (merge-pathnames real-path asd-file-name)))
(progn
(asdf:load-asd completed-asd-path)
(quicklisp:quickload system-name)
(use-package (intern (string-upcase system-name)))))))
(error ()
(error (format nil "super-load, ERROR! System (~a) was not found in:~%~a~%(Did you make a typo?)"
(car (last (split-sequence:split-sequence #\/ old-relative-path)))
(concatenate 'string (format nil "~a" (uiop:getcwd)) old-relative-path))))))) | 1,862 | Common Lisp | .lisp | 29 | 57.448276 | 106 | 0.691425 | jordan4ibanez/super-loader | 1 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 04f72fe6b1c4288ef63171b48fbed56f53f6541d47960c18c4e52666d64759ba | 24,981 | [
-1
] |
24,982 | tutorial.lisp | jordan4ibanez_super-loader/tutorial.lisp | (eval-when (:compile-toplevel :load-toplevel :execute)
;; This is how to load up super-loader.
(ql:quickload :super-loader)
(use-package :super-loader))
;; Great, now we have it loaded up, a true miracle.
;; Notice that we are walking into another eval-when.
;; This is because in the last scope of eval-when,
;; super-load still didn't exist as a symbol!
(eval-when (:compile-toplevel :load-toplevel :execute)
;; Let's load up that "my-cool-system" system!
;; To do a super-load, all you have to do, is this.
(super-load "my-cool-system")
(use-package :my-cool-system))
;; Now we can use it!
(cool)
;;"yeah, that's pretty cool. 8)"
;; But wait, there's one more thing I need to show you!
;; There is a hidden system in this tutorial. (Dramatic, I know!)
(eval-when (:compile-toplevel :load-toplevel :execute)
;; As you can see, you can build out a folder hierarchy using "/".
;; Notice: The end folder does not require "/".
;; Also, I don't recommend you put a "/" at the end either. It does it for you. :P
(super-load "my-cool-system/maybe-theres-a-secret-in-here/almost-there/my-secret-system")
(use-package :my-secret-system)
)
;; Now what's the secret?
(the-secret)
;; I suppose you're going to have to run the tutorial and find out! | 1,269 | Common Lisp | .lisp | 28 | 43.25 | 91 | 0.709208 | jordan4ibanez/super-loader | 1 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 1c17d1902d007db2d1bbecc221546b0df6d73a609b4055b90638b6e221d4538d | 24,982 | [
-1
] |
24,983 | my-cool-system.lisp | jordan4ibanez_super-loader/my-cool-system/my-cool-system.lisp | ;;;; my-cool-system.lisp
(in-package #:my-cool-system)
(export
'(cool))
(defun cool()
(print "yeah, that's pretty cool. 8)")) | 132 | Common Lisp | .lisp | 6 | 20 | 41 | 0.653226 | jordan4ibanez/super-loader | 1 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | a55b28ca370e1aef59c36eb91bade77215b9b15e320bf0b6b7611ccccc1b74f9 | 24,983 | [
-1
] |
24,984 | my-secret-system.lisp | jordan4ibanez_super-loader/my-cool-system/maybe-theres-a-secret-in-here/almost-there/my-secret-system/my-secret-system.lisp | ;;;; my-secret-system.lisp
(in-package #:my-secret-system)
(export
'(the-secret))
(defun the-secret()
(print "In a gran turismo 2 demo disk there are remnants of a cut drag racing mode!")) | 195 | Common Lisp | .lisp | 6 | 30.5 | 88 | 0.716578 | jordan4ibanez/super-loader | 1 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 9fffb0bcaa6cbee3c44c2ebc977d6c6782034d45fbcafae8dc390a2912db777e | 24,984 | [
-1
] |
24,985 | super-loader.asd | jordan4ibanez_super-loader/super-loader.asd | ;;;; super-loader.asd
(asdf:defsystem #:super-loader
:serial t
:description "A simple utility system to allow loading up local systems without jumping through hoops."
:author "jordan4ibanez"
:version "1.0.0"
:license "GPLV3"
:depends-on (#:split-sequence)
:components ((:file "package")
(:file "super-loader")))
| 342 | Common Lisp | .asd | 10 | 30.2 | 105 | 0.691843 | jordan4ibanez/super-loader | 1 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 469e258d3fb8de296d5b1643d2b1cc6edb11dfcd04854b8b302c8b10e09b13c7 | 24,985 | [
-1
] |
24,986 | my-cool-system.asd | jordan4ibanez_super-loader/my-cool-system/my-cool-system.asd | ;;;; my-cool-system.asd
(asdf:defsystem "my-cool-system"
:description "A seriously cool system. 8)"
:author "jordan4ibanez"
:version "1.0.0"
:license "GPLV3"
:components ((:file "package") ;; Or whatever you want to call your package file.
(:file "my-cool-system"))) | 292 | Common Lisp | .asd | 8 | 32.375 | 83 | 0.661972 | jordan4ibanez/super-loader | 1 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | debf945b010148ab8b39e8b08a02b5b1d9adab368fb44eaea11b8343af78b3fe | 24,986 | [
-1
] |
24,987 | my-secret-system.asd | jordan4ibanez_super-loader/my-cool-system/maybe-theres-a-secret-in-here/almost-there/my-secret-system/my-secret-system.asd | ;;;; my-secret-system.asd
(asdf:defsystem "my-secret-system"
:description "There is a secret hidden in this system. But what?"
:author "jordan4ibanez"
:version "1.0.0"
:license "GPLV3"
:components ((:file "package")
(:file "my-secret-system"))) | 270 | Common Lisp | .asd | 8 | 29.625 | 67 | 0.664122 | jordan4ibanez/super-loader | 1 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 8595783ab870bfaab988486d65e2ba795eed26d642482daf48ac5403c4e7c3ae | 24,987 | [
-1
] |
25,009 | package.lisp | inaimathi_forthlike/package.lisp | ;;;; package.lisp
(defpackage #:forthlike
(:use #:cl)
(:import-from #:alexandria #:with-gensyms)
(:import-from #:anaphora #:awhen #:aif #:it))
| 151 | Common Lisp | .lisp | 5 | 27.6 | 47 | 0.652778 | inaimathi/forthlike | 1 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 5b4436a6bbe5750ec61cf382a764b5053e552a492567ca6e59ec86b51284e0cc | 25,009 | [
-1
] |
25,010 | util.lisp | inaimathi_forthlike/util.lisp | (in-package :forthlike)
(define-condition forth-error (error)
((calls :initarg :calls :initform nil :accessor calls)))
(define-condition repl-break (forth-error) ())
(define-condition undefined-word (forth-error) ())
(define-condition stack-underflow (forth-error) ())
(define-condition unexpected-type (forth-error) ())
(defun ln (&optional (stream *standard-output*))
(write-char #\newline stream))
(defun fn-argcheck (arg-checks)
(when (some #'identity arg-checks)
(with-gensyms (elem tp)
`((loop for ,tp in '(,@arg-checks) for ,elem in (messages stack)
when (and ,tp (not (typep ,elem ,tp)))
do (error (make-instance 'unexpected-type)))))))
(defmacro fn ((&rest args) &body body)
(let ((arg-names (loop for a in args collect (if (listp a) (car a) a)))
(types (loop for a in args collect (when (listp a) (second a)))))
`(lambda (dict stack in)
(declare (ignorable dict stack in))
(unless (>= (len stack) ,(length args)) (error (make-instance 'stack-underflow)))
,@(fn-argcheck types)
,@(if args
`((let ,(loop for a in arg-names
collect `(,a (pop! stack)))
,@body))
body))))
(defmacro define-primitives (&rest name/def-list)
`(progn ,@(loop for (name def) on name/def-list by #'cddr
collect `(intern! *words* ,name ,def))))
(defun parse-num (str)
(multiple-value-bind (int end) (parse-integer str :junk-allowed t)
(if (and int (/= end (length str)) (eq #\. (aref str end)))
(ignore-errors
(multiple-value-bind (float f-end) (parse-integer str :start (+ end 1))
(+ int (float (/ float (expt 10 (- f-end end 1)))))))
int)))
(defmethod print-error ((message symbol) (word string) (stack dqueue) (err forth-error))
(declare (ignore err))
(format t "~a :: ~s " message word)
(print-stack stack)
(ln))
(defmethod print-stack ((q dqueue))
(format t "(~a) < " (len q))
(loop for wd in (messages q)
do (print-word wd) do (format t " "))
(format t ">"))
(defmethod print-word (word) (format t "~s" word))
(defmethod print-word ((word (eql nil))) (format t "FALSE"))
(defmethod print-word ((word (eql t))) (format t "TRUE"))
| 2,148 | Common Lisp | .lisp | 50 | 39.32 | 88 | 0.645285 | inaimathi/forthlike | 1 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 780c41332fef0e3dabcd99beb0300dcd65ad0b8916bb502708e060b2fbe41895 | 25,010 | [
-1
] |
25,011 | dqueue.lisp | inaimathi_forthlike/dqueue.lisp | (in-package #:forthlike)
(defclass dqueue ()
((messages :accessor messages :initform nil)
(last-cons :accessor last-cons :initform nil)
(len :accessor len :initform 0)))
(defmethod set-first! (message (q dqueue))
(with-slots (messages last-cons) q
(setf messages (list message)
last-cons messages)))
(defmethod enqueue! (message (q dqueue))
(with-slots (last-cons) q
(if (empty? q)
(set-first! message q)
(setf (cdr last-cons) (list message)
last-cons (cdr last-cons)))
(incf (len q))
(messages q)))
(defmethod push! (message (q dqueue))
(if (empty? q)
(set-first! message q)
(push message (messages q)))
(incf (len q))
(messages q))
(defmethod pop! ((q dqueue))
(if (empty? q)
(values nil nil)
(progn
(decf (len q))
(values (pop (messages q)) t))))
(defmethod empty? ((q dqueue)) (= 0 (len q)))
| 877 | Common Lisp | .lisp | 30 | 25.533333 | 48 | 0.642093 | inaimathi/forthlike | 1 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | ff14310add6ed1ccf253247d7428ae64f28bfc7a4fec5b1f1b40dd3dc8b250ac | 25,011 | [
-1
] |
25,012 | forthlike.lisp | inaimathi_forthlike/forthlike.lisp | (in-package #:forthlike)
(defparameter *words* (make-instance 'dqueue))
(defmethod pull! ((looking-for list) (s stream))
(loop for c = (read-char s nil :eof)
until (or (member c looking-for) (eq c :eof)) collect c into word
finally (return (values (coerce word 'string) c))))
(defmethod pull! ((looking-for character) (s stream))
(loop for c = (read-char s nil :eof)
until (or (eql c looking-for) (eq c :eof)) collect c into word
finally (return (values (coerce word 'string) c))))
(defmethod pull-word! ((s stream)) (pull! (list #\space #\newline) s))
(defmethod intern! ((dict dqueue) (name string) value)
(push! (list (intern name :keyword) value) dict))
(defmethod lookup ((dict dqueue) (word string))
(aif (assoc (intern word :keyword) (messages dict))
(values (second it) t)
(values nil nil)))
(defmethod numeric? ((str string))
(loop for c across str
unless (> 58 (char-code c) 47) do (return nil)
finally (return t)))
(defmethod parse-word ((dict dqueue) (word string))
(cond ((string= "" word) "")
((numeric? word) (parse-integer word :junk-allowed t))
(t (multiple-value-bind (wd found?) (lookup dict word)
(unless found? (error (make-instance 'undefined-word)))
wd))))
(defmethod eval-word ((dict dqueue) (stack dqueue) (in stream) word)
(push! word stack))
(defmethod eval-word ((dict dqueue) (stack dqueue) (in stream) (word string))
(unless (string= "" word) (call-next-method)))
(defmethod eval-word ((dict dqueue) (stack dqueue) (in stream) (word function))
(funcall word dict stack in))
(define-primitives
"bye" (fn () (error (make-instance 'repl-break)))
"." (fn (wd) (print-word wd) (ln))
".s" (fn () (print-stack stack) (ln))
"true" t
"false" nil
"dup" (fn (a) (push! a stack) (push! a stack))
"swap" (fn (a b)
(push! a stack)
(push! b stack))
"'" (fn () (push! (pull-word! in) stack))
"eval" (fn (wd) (eval-word dict stack in (parse-word dict wd)))
"\"" (fn () (push! (pull! #\" in) stack))
"+" (fn ((a number) (b number)) (push! (+ a b) stack))
"*" (fn ((a number) (b number)) (push! (* a b) stack))
"/" (fn ((a number) (b number)) (push! (/ a b) stack))
"-" (fn ((a number) (b number)) (push! (- a b) stack))
"=" (fn (a b) (push! (equal a b) stack))
">" (fn ((a number) (b number)) (push! (> a b) stack))
"<" (fn ((a number) (b number)) (push! (< a b) stack))
"not" (fn ((a boolean)) (push! (not a) stack))
"and" (fn ((a boolean) (b boolean)) (push! (and a b) stack))
"or" (fn ((a boolean) (b boolean)) (push! (or a b) stack))
"if" (fn ((true? boolean))
(loop for wd = (pull-word! in) until (string= wd "then")
when true? do (eval-word dict stack in (parse-word dict wd))))
":" (fn ()
(let ((name (pull-word! in))
(words (loop for wd = (pull-word! in)
until (string= wd ";")
if (string= wd "\"") collect (pull! #\" in)
else collect (parse-word dict wd))))
(intern! dict name (fn () (mapc (lambda (w) (eval-word dict stack in w)) words))))))
(defun repl ()
(let ((stack (make-instance 'dqueue)))
(handler-case
(loop (progn (format t "~~4>> ")
(multiple-value-bind (wd last-char) (pull! (list #\space #\newline) *standard-input*)
(handler-case
(unless (eql last-char :eof)
(eval-word *words* stack *standard-input*
(parse-word *words* wd)))
(stack-underflow (e) (print-error :stack-underflow wd stack e))
(unexpected-type (e) (print-error :unexpected-type wd stack e))
(undefined-word (e) (print-error :undefined-word wd stack e))))))
(repl-break () (format t "Cheers!")))))
| 3,649 | Common Lisp | .lisp | 79 | 41.987342 | 92 | 0.611552 | inaimathi/forthlike | 1 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 2a7076a48bcb75f509149f654fc0d95246bd26cdc69189d2b44b4ae3430a586e | 25,012 | [
-1
] |
25,013 | forthlike.asd | inaimathi_forthlike/forthlike.asd | ;;;; forthlike.asd
(asdf:defsystem #:forthlike
:serial t
:description "Describe forthlike here"
:author "Your Name <[email protected]>"
:license "Specify license here"
:depends-on (#:alexandria #:anaphora)
:components ((:file "package")
(:file "dqueue")
(:file "util")
(:file "forthlike")))
| 340 | Common Lisp | .asd | 11 | 25.818182 | 45 | 0.639144 | inaimathi/forthlike | 1 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | f09312d9d8cee7c151b71eab2890b4a0615ec84d483a689fefca2002cb7b6fb6 | 25,013 | [
-1
] |
25,034 | ui.lisp | leosongwei_cl-rts/ui.lisp | (defparameter *window-list* nil)
(sdl2-ttf-init)
(defparameter *font-default*
(open-ttf "/usr/share/fonts/TTF/DejaVuSansMono.ttf" 16))
(defclass window ()
((size-w :initform 0 :type 'integer
:accessor window-size-w)
(size-h :initform 0 :type 'integer
:accessor window-size-h)
(focus-x :initform 0.0 :type 'single-float
:accessor window-focus-x)
(focus-y :initform 0.0 :type 'single-float
:accessor window-focus-y)
(zoom :initform 1.0 :type 'single-float
:accessor window-zoom)
(max-fps :initform 60 :type integer
:accessor window-max-fps)
(sdl2-window :initform nil
:accessor window-sdl2-window)
(sdl2-window-id :initform -1
:accessor window-sdl2-window-id)
(sdl2-renderer :initform nil
:accessor window-sdl2-renderer)
(sdl2-surface :initform nil
:accessor window-sdl2-surface)
(frames :initform nil
:accessor window-frames)
(thread :initform nil
:accessor window-thread)))
(defun window-resize-handler (window w h)
(sdl2:set-window-size (window-sdl2-window window) w h)
(setf (window-sdl2-surface window)
(sdl2:get-window-surface (window-sdl2-window window)))
(setf (window-size-w window) w)
(setf (window-size-h window) h))
(defun close-window (window)
(if (typep (window-thread window)
'sb-thread:thread)
(sb-thread:terminate-thread (window-thread window)))
(sdl2:destroy-renderer (window-sdl2-renderer window))
(sdl2:destroy-window (window-sdl2-window window))
(setf (window-sdl2-renderer window) nil)
(setf (window-sdl2-window window) nil))
(defun clear-window (window)
(sdl2:render-clear (window-sdl2-renderer window)))
(defun update-window (window)
(sdl2:render-present (window-sdl2-renderer window)))
(defun make-window (&optional (title "CL-RTS") (w 640) (h 480))
(let* ((window (make-instance 'window))
(sdl2-window (sdl2:create-window :title title
:w w
:h h
:flags '(:shown :resizable)))
(sdl2-renderer (sdl2:create-renderer sdl2-window -1
'(:accelerated))))
(setf (window-sdl2-window window) sdl2-window)
(setf (window-sdl2-renderer window) sdl2-renderer)
(setf (window-sdl2-window-id window)
(sdl2:get-window-id sdl2-window))
(window-resize-handler window w h)
(sdl2:set-render-draw-blend-mode sdl2-renderer :blend)
window))
;; ------------------------------------------------------------
;; UI CLASS
(defun add-accessor (class-name slot-def)
(when (null (getf (cdr slot-def) :accessor))
(let* ((slot-name (car slot-def))
(accessor-name (intern (concatenate 'string
(symbol-name class-name)
"-"
(symbol-name slot-name)))))
(concatenate 'list slot-def `(:accessor ,accessor-name)))))
(defun add-initarg (slot-def)
(when (null (getf (cdr slot-def) :initarg))
(let* ((slot-name (car slot-def))
(initarg-name (intern (symbol-name slot-name) "KEYWORD")))
(concatenate 'list slot-def `(:initarg ,initarg-name)))))
(defmacro ui-class-def (name superclass-list slots &rest options)
(let* ((slots-with-accessor (mapcar (lambda (slot)
(add-accessor name slot))
slots))
(slots-with-accessor-and-initarg (mapcar #'add-initarg slots-with-accessor)))
`(defclass ,name ,superclass-list ,slots-with-accessor-and-initarg ,@options)))
;; Everything is a "frame"
(ui-class-def
frame ()
((size-h :initform 0 :type 'integer)
(size-w :initform 0 :type 'integer)
(pos-x :initform 0 :type 'integer)
(pos-y :initform 0 :type 'integer)
;; children
(child-list :initform nil :type 'list)
(child-size-w :initform -1 :type 'integer)
(child-size-h :initform -1 :type 'integer)
;; SDL
(sdl-surface :initform nil)
(surface-update-func :initform nil)
;; mouse
(event-mouse-down :initform nil)
(event-mouse-up :initform nil)
(event-mouse-motion :initform nil)
(event-mouse-wheel :initform nil)
;; key
(event-key-down :initform nil)
(event-key-up :initform nil)
(event-text-input :initform nil)))
;; An UI Window contains ONE or None(NIL) ui widget
(ui-class-def
ui-window (frame)
((color :initform '(255 0 0 128))
(sdl-renderer :initform nil)
(sdl-texture :initform nil)
(surface-update-func :initform nil)))
(defun ui-window-surface-update (ui-window)
(let* ((sdl-surface (frame-sdl-surface ui-window))
(pixel-format (sdl2:surface-format sdl-surface))
(color (ui-window-color ui-window))
(sdl-color (sdl2-map-rgba pixel-format
(nth 0 color) (nth 1 color)
(nth 2 color) (nth 3 color))))
(sdl2:fill-rect sdl-surface nil sdl-color)
;; TODO: blit child widget pixel map here!!!
(when (ui-window-sdl-texture ui-window)
(sdl2:destroy-texture (ui-window-sdl-texture ui-window)))
(setf (ui-window-sdl-texture ui-window)
(sdl2:create-texture-from-surface (ui-window-sdl-renderer ui-window) sdl-surface))))
(defun show-ui-window (ui-window)
(sdl2:render-copy (ui-window-sdl-renderer ui-window) (ui-window-sdl-texture ui-window)
:dest-rect (sdl2:make-rect (frame-pos-x ui-window)
(frame-pos-y ui-window)
(frame-size-w ui-window)
(frame-size-h ui-window))))
(defun make-ui-window (window w h &optional (x 0) (y 0))
(let ((ui-window (make-instance 'ui-window
:size-w w :size-h h
:pos-x x :pos-y y
:child-size-w (- w 8)
:child-size-h (- h 8)
:sdl-surface (make-surface w h)
:sdl-renderer (window-sdl2-renderer window)
:surface-update-func #'ui-window-surface-update)))
ui-window))
;; Button
(ui-class-def
ui-button (frame)
((text :initform "" :type 'string)
(text-surface :initform nil)
;; event
(event-mouse-motion :initform nil)
(event-mouse-up :initform nil)
(event-mouse-down :initform nil)
(press-func :initform nil)
;; looking
(color :initform '(255 0 0 128))
(pointed-at-p :initform nil)
(pressed-down-p :initform nil)
(activated-p :initform t)))
(defun ui-button-surface-update (ui-button)
(let ((looking :normal))
(when (ui-button-pointed-at-p ui-button)
(setf looking :pointed))
(when (ui-button-pressed-down-p ui-button)
(setf looking :pressed))
(when (not (ui-button-activated-p ui-button))
(setf looking :deactivated))
(case looking
;; todo
(otherwise (let* ((color (ui-button-color ui-button))
(surface (frame-sdl-surface ui-button))
(pixel-format (sdl2:surface-format surface))
(sdl-color (sdl2-map-rgba pixel-format
(nth 0 color) (nth 1 color)
(nth 2 color) (nth 3 color)))
(text-surface (ui-button-text-surface ui-button))
(text-w (sdl2:surface-width text-surface))
(text-h (sdl2:surface-height text-surface))
(center-x (/ (frame-size-w ui-button) 2))
(center-y (/ (frame-size-h ui-button) 2))
(pos-x (floor (- center-x (/ text-w 2))))
(pos-y (floor (- center-y (/ text-h 2)))))
(sdl2:fill-rect surface nil sdl-color)
(sdl2:blit-surface text-surface nil
surface
(sdl2:make-rect pos-x pos-y text-w text-h)))))))
(defun make-ui-button (frame text f)
(let* ((size-w (frame-child-size-w frame))
(size-h (frame-child-size-h frame))
(text-surface (render-text-as-surface text *font-default* 255 255 255 255))
(ui-button (make-instance 'ui-button
:size-h size-h :size-w size-w
:text text :text-surface text-surface
:sdl-surface (make-surface size-w size-h))))
(ui-button-surface-update ui-button)
ui-button))
| 8,812 | Common Lisp | .lisp | 194 | 33.974227 | 94 | 0.565612 | leosongwei/cl-rts | 1 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 330d75cd623e00d8076132457921e0a6dbbd78c722d1ead50692f19e5b12b086 | 25,034 | [
-1
] |
25,035 | text-render.lisp | leosongwei_cl-rts/text-render.lisp | (defun text-size (text font-ptr)
(let ((width 0)
(height 0))
(cffi:with-foreign-objects ((w :int) (h :int))
(cffi:with-foreign-string (text-ptr text)
(sdl2-ttf-size-text font-ptr text-ptr w h))
(setf width (cffi:mem-aref w :int))
(setf height (cffi:mem-aref h :int)))
(values width height)))
;; (text-size "The quick brown fox jumps over the lazy dog, 你好世界" *font-default*)
;; => 490 19
(defun render-text-as-surface (text font &optional (r 128) (g 128) (b 128) (a 255))
(let* ((surface (make-surface-from-ptr
(cffi:with-foreign-string (string text)
(sdl2-render-utf8-blended font string r g b a))))
(width (sdl2:surface-width surface))
(height (sdl2:surface-height surface)))
(values surface width height)))
;; (render-text-as-surface "The quick brown fox jumps over the lazy dog, 你好世界"
;; *font-default*
;; 0 255 0)
;; => #(pointer) 490 19
(defun split-paragraphs (text)
(let ((paragraphs nil)
(current-para (make-dynamic-string)))
(dotimes (i (length text))
(if (eq #\newline (aref text i))
(progn (push current-para paragraphs)
(setf current-para (make-dynamic-string)))
(vector-push-extend (aref text i) current-para)))
(push current-para paragraphs)
(reverse paragraphs)))
(defun substring (string start end)
(when (> end (length string))
(setf end (length string)))
(subseq string start end))
(defun sum-list (list)
(let ((sum 0))
(dolist (n list)
(incf sum n))
sum))
(defun render-multiline-paragrah (para font width r g b a)
(let ((cursor 0)
(line-length 1)
(surfaces nil))
(block :printing-lines
(loop ;; printing lines
(if (>= cursor (length para))
(return-from :printing-lines))
;; increasing loop
(block :increasing
(loop (let* ((line-text (substring para cursor (+ cursor line-length)))
(w (text-size line-text font)))
(if (< w width)
;; good
(progn (incf line-length)
(if (>= line-length (length para))
(return-from :increasing)))
;; bad
(return-from :increasing)))))
;; decreasing loop
(block :decreasing
(loop
(when (= 1 line-length)
(return-from :decreasing))
(let* ((line-text (substring para cursor (+ cursor line-length)))
(w (text-size line-text font)))
(if (< w width)
(return-from :decreasing)
(decf line-length)))))
;; print as surface
(let ((text (substring para cursor (+ cursor line-length))))
(incf cursor (length text))
(push (render-text-as-surface text font r g b a) surfaces))))
(reverse surfaces)))
(defun render-multiline-text-fixed-width (string font width
&optional (r 255) (g 255) (b 255) (a 255))
(let* ((paragraphs (split-paragraphs string))
(surfaces nil))
(dolist (para paragraphs)
(if (= 0 (length para))
(push (render-text-as-surface " " font r g b a) surfaces)
(dolist (s (render-multiline-paragrah para font width r g b a))
(push s surfaces))))
(setf surfaces (reverse surfaces))
(let* ((h-cursor 0)
(height (sum-list (mapcar #'sdl2:surface-height surfaces)))
(surface (make-surface width height)))
(dolist (s surfaces)
(sdl2:blit-surface s nil surface
(sdl2:make-rect 0 h-cursor
width (sdl2:surface-height s)))
(incf h-cursor (sdl2:surface-height s)))
(dolist (s surfaces)
(sdl2:free-surface s))
(values surface width height))))
| 4,053 | Common Lisp | .lisp | 96 | 31.541667 | 84 | 0.545501 | leosongwei/cl-rts | 1 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 40b34c7e77f6443f3536e7f4acf2e98c4f82d8e61abdcc9928d709810fa41609 | 25,035 | [
-1
] |
25,036 | utils.lisp | leosongwei_cl-rts/utils.lisp | (defun make-dynamic-string ()
(make-array 0 :adjustable t
:fill-pointer 0
:element-type 'character))
;; (let ((s (make-dynamic-string)))
;; (vector-push-extend #\a s)
;; (vector-push-extend #\b s)
;; s)
(defmacro mvb-let* (bindings &body body)
(let* ((exp (car bindings))
(vars (butlast exp))
(multi-val-exp (car (last exp)))
(rest-bindings (cdr bindings)))
(if rest-bindings
`(multiple-value-bind ,vars ,multi-val-exp
(mvb-let* ,rest-bindings ,@body))
`(multiple-value-bind ,vars ,multi-val-exp
,@body))))
;; (defun test-binding-0 ()
;; (values 1 2))
;; (defun test-binding-1 ()
;; (values 1 2 3))
;; (mvb-let* ((a b (test-binding-0))
;; (c d e (test-binding-1)))
;; (list a b c d e))
| 811 | Common Lisp | .lisp | 25 | 27.36 | 50 | 0.556688 | leosongwei/cl-rts | 1 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 7974cadf4ae1ca5f213a04be8d12713c129edd206aab240dbd3ec1ae0d0784f0 | 25,036 | [
-1
] |
25,037 | main.lisp | leosongwei_cl-rts/main.lisp | (ql:quickload 'sdl2)
(ql:quickload :cffi-libffi)
(load "utils.lisp")
(progn ;; video parameters
(defparameter *w* 640)
(defparameter *h* 480)
(defparameter *sdl2-window* nil)
(defparameter *sdl2-renderer* nil)
(defparameter *sdl2-surface* nil)
(defparameter *sdl2-pixel-buffer* nil))
(load "cffi.lisp")
(load "text-render.lisp")
(load "ui.lisp")
(defparameter *class-slots* (make-hash-table))
(defun parse-defclass-f (name slots)
(let ((slots-list '()))
(dolist (slot slots)
(let* ((slot-name (car slot))
(slot-attrib (cdr slot))
(slot-alloc (getf slot-attrib :allocation)))
(when (or (null slot-alloc)
(eq slot-alloc :instance))
(push slot-name slots-list))))
(setf (gethash name *class-slots*) (reverse slots-list))
(reverse slots-list)))
(defmacro class-def (name superclass-list slots &rest options)
(parse-defclass-f name slots)
`(defclass ,name ,superclass-list ,slots ,@options))
;;(gethash 'astro-obj *class-slots*)
(defun class-precedence-list (class)
(sb-mop:class-precedence-list class))
(defun export-obj (obj) ;; (slow)
(let* ((class (class-of obj))
(precedence (class-precedence-list class))
(result nil)
(avail-slots nil))
(dolist (class precedence)
(let* ((class-name (class-name class))
(slots (gethash class-name *class-slots*))) ;; a symbol
(dolist (slot slots)
(when (not (getf result slot))
(setf (getf result slot) t)
(push slot avail-slots)))))
(dolist (slot avail-slots)
(setf (getf result slot) (slot-value obj slot)))
result))
(load "objdef.lisp")
| 1,692 | Common Lisp | .lisp | 47 | 30.361702 | 68 | 0.638532 | leosongwei/cl-rts | 1 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 56cc649f04bdcc7921bb47273bf76a5c84e7a867bc313af992138cb0777e162d | 25,037 | [
-1
] |
25,038 | cffi.lisp | leosongwei_cl-rts/cffi.lisp | (defun init-sdl2 ()
(sdl2:init :everything))
(init-sdl2)
(cffi:load-foreign-library "libSDL2_image.so")
(cffi:load-foreign-library "libSDL2_ttf.so")
(cffi:load-foreign-library "./cutils/libcint.so")
;; C interface
(defun make-surface (w h)
(sdl2:create-rgb-surface w h 32
:r-mask #xff000000
:g-mask #x00ff0000
:b-mask #x0000ff00
:a-mask #x000000ff))
(defun make-surface-from-ptr (ptr)
(sdl2-ffi::make-sdl-surface :ptr ptr))
(cffi:defcfun ("SDL_MapRGBA" sdl2-map-rgba) :uint32
(format-ptr :pointer) (r :uint8) (g :uint8) (b :uint8) (a :uint8))
;; (format t "~X~%" (sdl2-map-rgba (sdl2:surface-format (make-surface 10 10)) 255 0 0 255))
;; > FF0000FF
;;---------------------------------------
;; SDL2_image
(cffi:defcfun ("IMG_Init" sdl2-img-init) :int
(init-flag :int))
(defun init-sdl2-img ()
"IMG_InitFlags:
IMG_INIT_JPG = 0x00000001,
IMG_INIT_PNG = 0x00000002,
IMG_INIT_TIF = 0x00000004,
IMG_INIT_WEBP = 0x00000008"
(sdl2-img-init 2))
(cffi:defcfun ("IMG_Quit" quit-sdl2-img) :void)
(init-sdl2-img)
(cffi:defcfun ("IMG_Load" sdl2-img-load) :pointer
(filepath :pointer))
(defun img-load (filepath)
(cffi:with-foreign-string (filepath-c filepath)
(let ((surface-ptr (sdl2-img-load filepath-c)))
(if (cffi:null-pointer-p surface-ptr)
(error (format nil "Image \"~A\" Load Failed" filepath))
(make-surface-from-ptr surface-ptr)))))
;;-----------------------------------------
;; SDL2_ttf
(cffi:defcfun ("TTF_Init" sdl2-ttf-init) :int) ;; Returns: 0 on success, -1 on any error
(cffi:defcfun ("TTF_Quit" sdl2-ttf-quit) :void)
(cffi:defcfun ("TTF_OpenFont" sdl2-ttf-openfont) :pointer
(filepath :pointer) (ptsize :int))
(defun open-ttf (path ptsize)
(cffi:with-foreign-string (filepath path)
(sdl2-ttf-openfont filepath ptsize)))
(cffi:defcfun ("TTF_CloseFont" close-ttf) :void
(font :pointer))
(cffi:defcfun ("wrapper_TTF_RenderUTF8_Blended" sdl2-render-utf8-blended) :pointer
(font :pointer) (string :pointer) (r :uint8) (g :uint8) (b :uint8) (a :uint8))
;; #define TTF_STYLE_NORMAL 0x00
;; #define TTF_STYLE_BOLD 0x01
;; #define TTF_STYLE_ITALIC 0x02
;; #define TTF_STYLE_UNDERLINE 0x04
;; #define TTF_STYLE_STRIKETHROUGH 0x08
(cffi:defcfun ("TTF_SetFontStyle" sdl2-ttf-setfontstyle) :void
(font :pointer) (style :int))
(defun set-font-style (font style-list)
(let ((style 0))
(dolist (s style-list)
(setf style
(logior style
(case s
(:normal 0)
(:bold 1)
(:italic 2)
(:underline 4)
(:strikethroug 8)
(otherwise 0)))))
(sdl2-ttf-setfontstyle font style)))
(cffi:defcfun ("TTF_SizeUTF8" sdl2-ttf-size-text) :int
(font :pointer) (text :pointer) (width-ptr :pointer) (height-ptr :pointer))
;; -----------------------------
;; sdl2-event
;; typedef enum
;; {
;; SDL_ADDEVENT, // 0
;; SDL_PEEKEVENT, // 1
;; SDL_GETEVENT // 2
;; } SDL_eventaction;
(cffi:defcfun ("SDL_PeepEvents" sdl2-peep-events) :int
(events :pointer)
(num-events :int)
(action :int)
(min-type :uint32)
(max-type :uint32))
(cffi:defcfun ("SDL_FlushEvents" sdl2-flushevents) :void
(min-type :uint32)
(max-type :uint32))
(cffi:defcfun ("SDL_WaitEvent" sdl2-waitevent) :int
(event-ptr :pointer))
(defun flush-events ()
(sdl2-flushevents #.(sdl2::enum-value 'sdl2-ffi:sdl-event-type :firstevent)
#.(sdl2::enum-value 'sdl2-ffi:sdl-event-type :lastevent)))
(defun get-next-event ()
"SDL2 shares a global event queue, all events from all windows
are in this queue.
The event get from this function must be free, after use."
(let* ((event (sdl2:new-event))
(event-ptr (sdl2-ffi::sdl-event-ptr event)))
(sdl2-peep-events event-ptr
1
#.(sdl2::enum-value 'sdl2-ffi::sdl-eventaction :getevent)
#.(sdl2::enum-value 'sdl2-ffi:sdl-event-type :firstevent)
#.(sdl2::enum-value 'sdl2-ffi:sdl-event-type :lastevent))
event))
(defun wait-sdl-event ()
(let* ((event (sdl2:new-event))
(event-ptr (sdl2-ffi::sdl-event-ptr event)))
(sdl2-waitevent event-ptr)
event))
| 4,410 | Common Lisp | .lisp | 114 | 32.754386 | 91 | 0.608329 | leosongwei/cl-rts | 1 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 3167e5526ee25d23a3ced26ca36964e48cbd7854ab3b1df59b1afcd921c5e056 | 25,038 | [
-1
] |
25,039 | objdef.lisp | leosongwei_cl-rts/objdef.lisp | ;; -----------------------------------------------------
;; Astronomical Object
(class-def
astro-obj ()
((mass :initarg :mass
:initform 1.0
:accessor astro-obj-mass
:type 'float)
(radius :initarg :radius
:initform 1.0
:accessor astro-obj-radius
:type 'float)
;; orbiting around other astro obj?
(orbiting :initarg :orbiting
:initform nil
:accessor astro-obj-orbiting)
(orbit-angle :initarg :orbit-angle
:initform 0
:accessor astro-obj-orbit-angle
:type 'integer)
(orbit-radius :initarg :orbit-radius
:initform 1.0
:accessor astro-obj-orbit-radius
:type 'float)
;; if orbiting is NIL, use the abusolute position
(pos-x :initarg :pos-x
:initform 0.0
:accessor astro-obj-pos-x)
(pos-y :initarg :pos-y
:initform 0.0
:accessor astro-obj-pos-y)
(population :initarg :population
:initform nil
:accessor astro-obj-population)
(facilities :initarg :facilities
:initform nil
:accessor astro-obj-facilities))
(:documentation "The basic astronomical object, including stars, planets."))
(class-def
star (astro-obj)
((brightness :initarg :brightness
:initform 1.0
:accessor star-brightness
:type 'float)
(radiation :initarg :radiation
:initform 1.0
:accessor star-radiation
:type 'float)
(age :initarg :age
:initform 0.0
:accessor star-age
:type 'float)
(type :initarg :type
:initform :star
:accessor star-type
:type 'symbol
:documentation "Valid values: :star :supernova :black-hole :molecular-cloud")))
(class-def
planet (astro-obj)
((env :initarg :env
:initform 0.0
:accessor planet-env
:type 'float
:documentation "Basic environment value, `")
(ecosys :initarg :ecosys
:initform 0.0
:accessor planet-ecosys
:type 'float
:documentation "Ecosystem value")
(resources :initarg :resources
:initform nil
:accessor planet-resources
:type 'list)
(type :initarg :type
:initform :rocky
:accessor planet-type
:type 'symbol
:documentation "Valid values: :rocky Rocky planet, :gas Gas gaint.")))
;; ---------------------------------------------------------------
;; Facilities
(class-def
facility ()
((basic-strength :initarg :basic-strength
:initform 100
:accessor facility-basic-strength
:type 'integer)
(actual-strength :initarg :actual-strength
:initform 100
:accessor facility-actual-strength
:type 'integer)
(cost :initarg :cost
:initform nil
:accessor facility-cost)
(icon :initarg :icon
:initform nil
:accessor facility-icon)))
| 3,046 | Common Lisp | .lisp | 96 | 23.114583 | 87 | 0.564686 | leosongwei/cl-rts | 1 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 3ba7ee0802a29acf3757c047cee2b4e65bca01d753be6a556c0b10a71350c9f0 | 25,039 | [
-1
] |
25,061 | sigil.asd | equwal_sigil/sigil.asd | ;;;; sigil.asd
(asdf:defsystem #:sigil
:description "Sigils for Common Lisp documentation."
:author "Spenser Truex <[email protected]>"
:license "GNU GPL v3"
:version "0.0.1"
:serial t
:depends-on (#:sb-introspect)
:components ((:file "package")
(:file "sigil")))
| 298 | Common Lisp | .asd | 10 | 25.8 | 54 | 0.655052 | equwal/sigil | 1 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 7d4fcdb1553eafa2600201deab2bd0a2d729c32c826ad0a43f3905f43bf6f1e0 | 25,061 | [
-1
] |
25,078 | paquetes.lisp | josrr_guerra-espacial/paquetes.lisp | (in-package #:cl-user)
(defpackage #:guerra-espacial
(:nicknames :guesp)
(:use #:clim
#:clim-lisp
#:uiop)
(:export #:main
#:guerra-espacial-entry-point))
| 188 | Common Lisp | .lisp | 8 | 18.25 | 42 | 0.592179 | josrr/guerra-espacial | 1 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | c02c58b780b0d15e57b71da5e178b1e2b43fe04b6f75603dcbb6b9947465edb4 | 25,078 | [
-1
] |
25,079 | animaciones.lisp | josrr_guerra-espacial/animaciones.lisp | (in-package #:guerra-espacial)
(defun spacewar! (pane)
(dibuja-estrellas pane)
(dibuja-estrella pane (/ *ancho* 2) (/ *alto* 2))
(loop for obj in (espacio-objs pane)
if (not (null (getf obj :func))) do
(funcall (getf obj :func) pane obj))
(mapcar #'explota-obj (hay-colision-p pane)))
(defun munching-squares (pane)
(declare (optimize (speed 3) (safety 0)))
(draw-rectangle* pane 0 0 *ancho* *alto* :filled t :ink +black+)
(loop with cuantos double-float = *ms-num-cuadros*
with cuantos-1 fixnum = (round (1- cuantos))
with total double-float = (* cuantos cuantos)
with num-cuadro fixnum = (espacio-num-cuadro pane)
with ancho double-float = (min (/ *ancho-df* cuantos) (/ *alto-df* cuantos))
with ancho/2 double-float = (/ ancho 2.0d0)
with cuantos-si double-float = 0.0d0
for x from 0 to cuantos-1 and xmed double-float from ancho/2 by ancho do
(loop for y from 0 to cuantos-1 and ymed double-float from ancho/2 by ancho
if (< (logxor x y) num-cuadro) do
(draw-point* pane xmed ymed :ink +darkslategrey+ :line-thickness ancho)
(incf cuantos-si))
finally (if (>= cuantos-si total)
(setf (espacio-num-cuadro pane) 1)
(incf (the fixnum (espacio-num-cuadro pane))))))
(defun minskytron (pane)
(let* ((datos (espacio-datos pane))
(x (if datos (car datos) -19/24))
(y (if datos (cadr datos) -1015/121))
(δ 7381/5040)
(ω 5040/7381)
(ancho (bounding-rectangle-width (sheet-region pane)))
(alto (bounding-rectangle-height (sheet-region pane))))
(let ((pixmap (espacio-pixmap pane)))
(when pixmap
(when (= 1 (espacio-num-cuadro pane))
(draw-rectangle* pixmap 0 0 ancho alto :filled t :ink +black+))
(loop for i from 0 below 1000
for px = (+ *ancho/2* x) and py = (- *alto/2* y)
for color = (/ (log (incf (espacio-num-cuadro pane))) 255 10)
if (and (>= px 0) (< px ancho) (>= py 0) (< py alto)) do
(draw-point* pixmap px py
:ink (clim:make-rgb-color (random 1.0) 0.75
(if (> color 1) 1 color))
:line-thickness 1)
end do
(setf y (- y (floor x δ))
x (+ x (floor y ω))))
(if (null (espacio-datos pane))
(setf (espacio-datos pane) (list x y))
(setf (car (espacio-datos pane)) x
(cadr (espacio-datos pane)) y))
(copy-from-pixmap pixmap 0 0
(bounding-rectangle-width (sheet-region pane))
(bounding-rectangle-height (sheet-region pane))
pane 0 0)))))
| 2,891 | Common Lisp | .lisp | 57 | 38.210526 | 89 | 0.540856 | josrr/guerra-espacial | 1 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 110d48f57b86f9e68d190ca3984b645f6769fe30d7aee67751689c9bc9cd84a2 | 25,079 | [
-1
] |
25,080 | parametros.lisp | josrr_guerra-espacial/parametros.lisp | (in-package #:guerra-espacial)
(defparameter *teclas* '((:ot2
:izq (:|a| :|A|)
:der (:|d| :|D|)
:empuje (:|s| :|S|)
:fuego (:|w| :|W|)
:hiperespacio (:|e| :|E|))
(:ot1
:izq (:|j| :|J|)
:der (:|l| :|L|)
:empuje (:|k| :|K|)
:fuego (:|i| :|I|)
:hiperespacio (:|o| :|O|))))
(declaim (type double-float *ancho-df* *alto-df* *ancho-df/2* *alto-df/2*))
(defparameter *ancho* 1024)
(defparameter *alto* 1024)
(defparameter *ancho/2* 512)
(defparameter *alto/2* 512)
(defparameter *ancho-df* (coerce *ancho* 'double-float))
(defparameter *alto-df* (coerce *alto* 'double-float))
(defparameter *ancho-df/2* (/ *ancho-df* 2.0d0))
(defparameter *alto-df/2* (/ *alto-df* 2.0d0))
(declaim (type double-float *max-x* *max-y* *min-x* *min-y*))
(defparameter *max-x* (/ *ancho* 2.0d0))
(defparameter *max-y* (/ *alto* 2.0d0))
(defparameter *min-x* (- (1- *max-x* )))
(defparameter *min-y* (- (1- *max-y* )))
(declaim (type double-float *desp-x* *pausa*))
(defparameter *pausa* (/ 40.0d0))
(defparameter *ruta-del-sistema* (asdf:component-pathname (asdf:find-system 'guerra-espacial)))
(defparameter *desp-x* (/ (* *pausa* 8192) (* 24 60 60)))
(defparameter *ancho-mapa-estelar* 8192)
(defparameter *max-x-mapa-estelar* (1- *ancho-mapa-estelar*))
(declaim (type double-float *radio-estrella* *2pi* *aceleracion-angular-nave* *aceleracion-nave*
*gravedad*))
(defparameter *radio-estrella* 5.0d0)
(defparameter *2pi* (* 2.0d0 pi))
(defparameter *aceleracion-angular-nave* (/ (* 8.0d0 pi) 51472.0d0))
(defparameter *aceleracion-nave* 12.0d0)
(defparameter *paso-nave* 2)
(defparameter *gravedad* (/ 14.0d0))
(declaim (type double-float *radio-colision-1* *radio-colision-2*))
(defparameter *radio-colision-1* 96d0)
(defparameter *radio-colision-2* 48d0)
(declaim (type double-float *torpedo-vel-inicial* *torpedo-space-warpage* *hiperespacio-probabilidad-explosion*))
(defparameter *duracion-explosion* 16)
(defparameter *duracion-torpedos* 120)
(defparameter *tamaño-torpedos* 512)
(defparameter *tamaño-nave* 1024)
(defparameter *numero-de-torpedos* 32)
(defparameter *torpedo-vel-inicial* 16.0d0)
(defparameter *torpedo-space-warpage* 512.0d0)
(defparameter *combustible* 1280)
(defparameter *hiperespacio-num-saltos* 8)
(defparameter *hiperespacio-tiempo-1* 48)
(defparameter *hiperespacio-tiempo-2* 32)
(defparameter *hiperespacio-tiempo-enfriamiento* 128)
(defparameter *hiperespacio-probabilidad-explosion* (/ 2.0d0 *hiperespacio-num-saltos*))
;; Munching squares
(declaim (type double-float *ms-cuantos*))
(defparameter *ms-num-cuadros* 64.0d0)
| 2,905 | Common Lisp | .lisp | 61 | 41.52459 | 113 | 0.620544 | josrr/guerra-espacial | 1 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 7fc9170a9eb214d3a577329289177d36f119f81674f30b3f1d40c30053483f2e | 25,080 | [
-1
] |
25,081 | datos-naves.lisp | josrr_guerra-espacial/datos-naves.lisp | ;;;; This data is taken from the file published in the following URL
;;;; https://www.masswerk.at/spacewar/sources/spacewar_2b_2apr62.txt
(in-package #:guerra-espacial)
(defparameter *naves* `((:ot1 (:forma (#o111131
#o111111
#o111111
#o111163
#o311111
#o146111
#o111114
#o700000)
:x 256.0d0
:y 256.0d0
:theta ,pi))
(:ot2 (:forma (#o013113
#o113111
#o116313
#o131111
#o161151
#o111633
#o365114
#o700000)
:x -256.0d0
:y -256.0d0
:theta 0.0d0))))
| 1,247 | Common Lisp | .lisp | 25 | 16.92 | 71 | 0.258804 | josrr/guerra-espacial | 1 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 8bcf21f74c18c1e54eb91e08f6dffdfa7080fce061c939f5ab30d007baa71ed0 | 25,081 | [
-1
] |
25,082 | nave.lisp | josrr_guerra-espacial/nave.lisp | (in-package #:guerra-espacial)
(declaim (inline toroidalizar actualiza-posicion-obj actualiza-direccion-obj
actualiza-mom-angular gravedad empuje-nave))
(defun hay-colision-p (pane)
(declare (optimize (speed 3)))
(loop for todos on (remove nil (espacio-objs pane) :key (lambda (o) (getf o :colisiona)))
for obj1 = (car todos)
for obj1-es-nave = (eq :nave (getf obj1 :tipo))
for x1 double-float = (if obj1-es-nave (getf obj1 :xm) (getf obj1 :x))
and y1 double-float = (if obj1-es-nave (getf obj1 :ym) (getf obj1 :y))
append (remove-duplicates (mapcan (lambda (obj2)
(let* ((obj2-es-nave (eq :nave (getf obj2 :tipo)))
(x2 (getf obj2 :x))
(y2 (getf obj2 :y))
(dx (abs (- (if obj2-es-nave (the double-float (getf obj2 :xm)) x2) x1)))
(dy (abs (- (if obj2-es-nave (the double-float (getf obj2 :ym)) y2) y1))))
(declare (type double-float x2 y2 dx dy))
(when (and (< dx *radio-colision-1*)
(< dy *radio-colision-1*)
(< (+ dx dy) *radio-colision-2*))
(list obj1 obj2))))
(cdr todos)))))
(defun toroidalizar (obj)
(declare (optimize (speed 3) (safety 0)))
(let ((x (getf obj :x))
(y (getf obj :y)))
(declare (type double-float x y))
(if (< x *min-x*)
(setf (getf obj :x) (+ x *ancho-df*))
(when (> x *max-x*)
(setf (getf obj :x) (- x *ancho-df*))))
(if (< y *min-y*)
(setf (getf obj :y) (+ y *alto-df*))
(when (> y *max-y*)
(setf (getf obj :y) (- y *alto-df*))))))
(defun actualiza-posicion-obj (obj)
(declare (optimize (speed 3) (safety 0)))
(let* ((x0 (getf obj :x))
(y0 (getf obj :y))
(dx (getf obj :dx))
(dy (getf obj :dy))
(x (+ x0 (/ dx 8.0d0)))
(y (+ y0 (/ dy 8.0d0))))
(declare (type double-float x0 y0 dx dy))
(setf (getf obj :y) y
(getf obj :x) x)
(toroidalizar obj)
(values (getf obj :x) (getf obj :y))))
(defun explosion (pane obj)
(declare (optimize (speed 3) (safety 0)))
(multiple-value-bind (x y) (actualiza-posicion-obj obj)
(declare (type double-float x y))
(let ((x (+ *ancho-df/2* x))
(y (- *alto-df/2* y)))
(loop for m fixnum from (floor (the fixnum (getf obj :tamaño)) 8) downto 1
for factor double-float = (random (if (> m 96) 256.0d0 64.0d0)) do
(draw-point* pane
(+ x (* factor (- (random 1.0d0) 0.5d0)))
(+ y (* factor (- (random 1.0d0) 0.5d0)))
:ink (if (zerop (random 2))
+light-steel-blue+ +royalblue+)
:line-thickness 4))))
(when (zerop (decf (the fixnum (getf obj :contador))))
(setf (getf obj :func) nil
(espacio-objs pane) (remove obj (espacio-objs pane)))))
(defun explota-obj (obj &optional (contador *duracion-explosion*))
(when (and (eq :nave (getf obj :tipo)))
(setf (getf obj :x) (getf obj :xm)
(getf obj :y) (getf obj :ym)))
(setf (getf obj :contador) (or contador *duracion-explosion*)
(getf obj :dx) 0.0d0
(getf obj :dy) 0.0d0
(getf obj :colisiona) nil
(getf obj :func) #'explosion))
(defun gravedad (obj)
(declare (optimize (speed 3) (safety 0)))
(let* ((es-nave (and (eq :nave (getf obj :tipo))))
(x (getf obj (if es-nave :xm :x)))
(y (getf obj (if es-nave :ym :y)))
(t1 (+ (expt (* x *gravedad*) 2.0d0)
(expt (* y *gravedad*) 2.0d0))))
(declare (type double-float x y t1))
(if (< t1 *radio-estrella*)
(progn
(explota-obj obj 32)
(values))
(let ((t1 (/ (* t1 (sqrt t1)) 2.0d0)))
(values (/ (- x) t1)
(/ (- y) t1))))))
(defun empuje-nave (nave aceleracion)
(declare (optimize (speed 3) (safety 0))
(type double-float aceleracion))
(values (/ (the double-float (getf nave :sen)) aceleracion)
(/ (the double-float (getf nave :cos)) aceleracion)))
(defun actualiza-direccion-obj (obj am)
(declare (optimize (speed 3) (safety 0))
(type double-float am))
(let* ((theta (getf obj :theta))
(theta1 (+ theta am)))
(declare (type double-float theta theta1))
(setf (getf obj :theta)
(if (> theta1 *2pi*) (- theta1 *2pi*)
(if (< theta1 (- *2pi*)) (+ theta1 *2pi*)
theta1)))) )
(defun actualiza-mom-angular (nave am izq der)
(declare (optimize (speed 3) (safety 0))
(type double-float am))
(if izq
(incf am *aceleracion-angular-nave*)
(when der
(decf am *aceleracion-angular-nave*)))
(setf (getf nave :mom-angular) am))
(defun mueve-nave (nave)
(let* ((ctrls (getf nave :controles))
(izq (member :izq ctrls))
(der (member :der ctrls))
(empuje (member :empuje ctrls)))
(actualiza-direccion-obj nave
(actualiza-mom-angular nave
(getf nave :mom-angular)
izq der))
(multiple-value-bind (bx by) (gravedad nave)
(when bx
(when (and empuje (> (getf nave :combustible) 0))
(multiple-value-bind (d-bx d-by) (empuje-nave nave *aceleracion-nave*)
(incf by d-by)
(decf bx d-bx)))
(incf (getf nave :dy) by)
(incf (getf nave :dx) bx)
(actualiza-posicion-obj nave)))
(values empuje izq der)))
(defun dibuja-minskytron (pane num-puntos nave-x nave-y x y d w)
(loop
with desp-x = (+ nave-x *ancho-df/2*) and desp-y = (- *alto-df/2* nave-y)
with i = x and j = y
repeat num-puntos do
(draw-point* pane (+ desp-x i) (- desp-y j) :ink +skyblue+ :line-thickness 4)
(setf j (- j (floor i d))
i (+ i (floor j w)))))
(defun dibuja-gases-nave (pane x y sen cos color-1 color-2 &optional (max-largo 16))
(declare (optimize (speed 3) (safety 0))
(type double-float x y sen cos)
(type fixnum max-largo))
(let ((largo (random max-largo))
(sen (* 2 sen))
(cos (* 2 cos)))
(declare (type double-float sen cos)
(type fixnum largo))
(loop repeat largo
for x double-float from x by sen
for y double-float from y by cos
for dx double-float = (- 1.0d0 (random 2.0d0)) do
(draw-point* pane (+ dx x) y :ink color-1 :line-thickness 3)
(draw-point* pane (- x dx) y :ink color-2 :line-thickness 1))))
(defun dibuja-nave (pane nave &optional empuje izq der (paso *paso-nave*) (ciclo 0))
(declare (optimize (speed 3) (safety 0))
(type fixnum ciclo))
(let* ((xo (getf nave :x))
(yo (getf nave :y))
(x (+ *ancho-df/2* xo))
(y (- *alto-df/2* yo))
(abs-paso (coerce (abs paso) 'double-float))
(sen (getf nave :sen))
(cos (getf nave :cos))
(ssn (* abs-paso sen))
(scn (* abs-paso cos))
(ssm (if (minusp paso) (- ssn) ssn))
(scm (if (minusp paso) (- scn) scn))
(ssc (+ ssn scm))
(csn (- ssn scm))
(ssd (+ scn ssm))
(csm (- scn ssm)))
(declare (type double-float xo yo x y ssn scn ssm scm ssc csn ssd csm abs-paso sen cos)
(type fixnum paso))
(loop with guardada = nil
for valor in (getf nave :desc) do
(with-drawing-options (pane :ink +yellow+ :line-thickness 1 :line-cap-shape :round)
(draw-point* pane (the fixnum (round x)) (the fixnum (round y)))
(case valor
((0 1) (incf x ssn) (incf y scn) nil)
(2 (incf x scm) (decf y ssm) nil)
(3 (incf x ssc) (incf y csm) nil)
(4 (decf x scm) (incf y ssm) nil)
(5 (incf x csn) (incf y ssd) nil)
(6 (if guardada
(setf x (car guardada)
y (cdr guardada)
guardada nil)
(setf guardada (cons x y))))
(7 (when (zerop ciclo)
(dibuja-nave pane nave empuje izq der (- paso) 1))
(setf (getf nave :xm) (/ (+ (- x *ancho-df/2*) xo) 2)
(getf nave :ym) (/ (+ (- *alto-df/2* y) yo) 2))
(return t)))))
(when empuje (dibuja-gases-nave pane x y sen cos +darkorange+ +white+))
(when der (dibuja-gases-nave pane (+ x (* 11d0 cos)) (+ y (* -11d0 sen)) cos (- sen) +snow3+ +white+ 6))
(when izq (dibuja-gases-nave pane (+ x (* -11d0 cos)) (+ y (* 11d0 sen)) (- cos) sen +snow3+ +white+ 6))))
(defun maneja-torpedo (pane torpedo)
(multiple-value-bind (bx by) (gravedad torpedo)
(when bx (incf (getf torpedo :dy) by)
(incf (getf torpedo :dx) bx)
(let ((warpage (* 512.0d0 *torpedo-space-warpage*)))
(declare (type double-float warpage))
(incf (getf torpedo :dy) (/ (getf torpedo :x) warpage))
(incf (getf torpedo :y) (/ (getf torpedo :dy) 8.0d0))
(incf (getf torpedo :dx) (/ (getf torpedo :y) warpage))
(incf (getf torpedo :x) (/ (getf torpedo :dx) 8.0d0)))
(toroidalizar torpedo)))
(let ((x (+ *ancho-df/2* (getf torpedo :x)))
(y (- *alto-df/2* (getf torpedo :y))))
(draw-point* pane x y :ink +blue+ :line-thickness 7)
(draw-point* pane x y :ink +white+ :line-thickness 4))
(if (> (getf torpedo :contador) 0)
(progn
(when (and (null (getf torpedo :colisiona))
(= (- *duracion-torpedos* 12) (getf torpedo :contador)))
(setf (getf torpedo :colisiona) t))
(decf (getf torpedo :contador)))
(setf (getf torpedo :contador) *duracion-explosion*
(getf torpedo :func) #'explosion)))
(defun nuevo-torpedo (nave num)
(declare (optimize (speed 3))
(type fixnum num))
(let* ((x (getf nave :x))
(y (getf nave :y))
(dx (getf nave :dx))
(dy (getf nave :dy))
(sen (getf nave :sen))
(cos (getf nave :cos)))
(declare (type double-float sen cos x y dx dy))
(list :tipo :torpedo
:nombre (alexandria:symbolicate 'torpedo-
(getf nave :nombre)
'- (princ-to-string num))
:func #'maneja-torpedo
:x (- x (* 8.0d0 sen))
:y (+ y (* 8.0d0 cos))
:dx (- dx (* *torpedo-vel-inicial* sen))
:dy (+ dy (* *torpedo-vel-inicial* cos))
:sen sen
:cos cos
:colisiona nil
:contador *duracion-torpedos*
:tamaño *tamaño-torpedos*
:nave nave)))
(defun sal-del-hiperespacio (pane nave)
(if (zerop (getf nave :contador))
(if (= (getf nave :hiperespacio) (random *hiperespacio-num-saltos*))
(explota-obj nave)
(setf (getf nave :hiperespacio-tiempo-enfriamiento) *hiperespacio-tiempo-enfriamiento*
(getf nave :colisiona) t
(getf nave :func) #'maneja-nave))
(progn
(draw-circle* pane
(+ *ancho-df/2* (getf nave :x)) (- *alto-df/2* (getf nave :y))
(/ *hiperespacio-tiempo-2* (getf nave :contador))
:filled nil
:ink +skyblue+
:line-thickness 2)
(decf (getf nave :contador)))))
(defun hiperespacio (nave)
(let* ((contador (getf nave :contador)))
(lambda (pane nave)
(if (> (getf nave :contador) 0)
(let ((c (- contador (getf nave :contador))))
(decf (getf nave :contador))
(dibuja-minskytron pane c (getf nave :x) (getf nave :y) -12 12 -67 -1)
(dibuja-minskytron pane c (getf nave :x) (getf nave :y) 12 12 1 (+ (floor c 4) 67)))
(setf (getf nave :x) (- (random *ancho-df*) *ancho-df/2*)
(getf nave :y) (- (random *ancho-df*) *alto-df/2*)
(getf nave :xm) (getf nave :x)
(getf nave :ym) (getf nave :y)
(getf nave :theta) (random *2pi*)
(getf nave :sen) (sin (getf nave :theta))
(getf nave :cos) (cos (getf nave :theta))
(getf nave :contador) *hiperespacio-tiempo-2*
(getf nave :func) #'sal-del-hiperespacio)))))
(defun salta-al-hiperespacio (pane nave)
(declare (ignore pane))
(decf (getf nave :hiperespacio))
(setf (getf nave :contador) *hiperespacio-tiempo-1*
(getf nave :colisiona) nil
(getf nave :func) (hiperespacio nave)))
(defun dispara-torpedo (pane nave)
(when (> (getf nave :torpedos) 0)
(push (nuevo-torpedo nave (getf nave :torpedos))
(espacio-objs pane))
(decf (getf nave :torpedos))))
(defun maneja-nave (pane nave)
(setf (getf nave :sen) (sin (getf nave :theta))
(getf nave :cos) (cos (getf nave :theta)))
(multiple-value-bind (empuje izq der) (mueve-nave nave)
(dibuja-nave pane nave (and empuje
(> (getf nave :combustible) 0))
izq der)
(when (and empuje (> (getf nave :combustible) 0))
(decf (getf nave :combustible))))
(when (member :fuego (getf nave :controles))
(if (zerop (getf nave :disparando))
(progn
(setf (getf nave :disparando) 32)
(dispara-torpedo pane nave))))
(when (> (getf nave :disparando) 0)
(decf (getf nave :disparando)))
(when (and (member :hiperespacio (getf nave :controles))
(> (getf nave :hiperespacio) 0)
(zerop (getf nave :hiperespacio-tiempo-enfriamiento)))
(salta-al-hiperespacio pane nave))
(when (> (getf nave :hiperespacio-tiempo-enfriamiento) 0)
(decf (getf nave :hiperespacio-tiempo-enfriamiento))))
(defun carga-naves (lista)
(mapcar (lambda (datos)
(let ((nave (cadr datos)))
(list :tipo :nave
:nombre (car datos)
:func #'maneja-nave
:x (or (getf nave :x) 0.0d0)
:y (or (getf nave :y) 0.0d0)
:dx 0.0d0
:dy 0.0d0
:sen 0.0d0
:cos 0.0d0
:mom-angular 0.0d0
:theta (or (getf nave :theta) 0.0d0)
:vel-angular 0.0d0
:combustible *combustible*
:torpedos *numero-de-torpedos*
:colisiona t
:contador 0
:controles nil
:hiperespacio *hiperespacio-num-saltos*
:hiperespacio-tiempo-enfriamiento 0
:tamaño *tamaño-nave*
:disparando 0
:xm (or (getf nave :x) 0.0d0)
:ym (or (getf nave :y) 0.0d0)
:desc (loop for palabra in (getf nave :forma)
append
(loop for v across (format nil "~o" palabra)
collect (- (char-code v) (char-code #\0)))))))
lista))
(defun dame-nave (pane nombre)
(find nombre (espacio-objs pane)
:key (lambda (n) (getf n :nombre))))
(defun agrega-control-nave (gadget nombre-nave control)
(let ((nave (dame-nave gadget nombre-nave)))
(bt:with-lock-held ((guesp-bloqueo *application-frame*))
(push control (getf nave :controles)))))
(defun quita-control-nave (gadget nombre-nave control)
(let ((nave (dame-nave gadget nombre-nave)))
(bt:with-lock-held ((guesp-bloqueo *application-frame*))
(setf (getf nave :controles)
(remove control (getf nave :controles))))))
| 16,239 | Common Lisp | .lisp | 353 | 34.05949 | 122 | 0.513529 | josrr/guerra-espacial | 1 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | ee12d2a9e994756dff84ca459c56ecd1f6a185b2f24f83aedd974fd1b5a0b224 | 25,082 | [
-1
] |
25,083 | datos-estrellas.lisp | josrr_guerra-espacial/datos-estrellas.lisp | ;;;; This data is taken from the file published in the following URL
;;;; https://www.masswerk.at/spacewar/sources/stars_by_prs_for_sw2b_mar62.txt
;;;; The starfield data (13 Mar. 1962) for the Expensive Planetarium by Peter Samson, originally for Spacewar! 2B and included in all versions of Spacewar!.
(in-package #:guerra-espacial)
(defparameter *estrellas*
(carga-estrellas
'((1 (1537 371 87 Taur Aldebaran)
(1762 -189 19 Orio Rigel)
(1990 168 58 Orio Betelgeuze)
(2280 -377 9 CMaj Sirius)
(2583 125 10 CMin Procyon)
(3431 283 32 Leon Regulus)
(4551 -242 67 Virg Spica)
(4842 448 16 Boot Arcturus)
(6747 196 53 Aqil Altair))
(2 (1819 143 24 Orio Bellatrix)
(1884 -29 46 Orio)
(1910 -46 50 Orio)
(1951 -221 53 Orio)
(2152 -407 2 CMaj)
(2230 375 24 Gemi)
(3201 -187 30 Hyda Alphard)
(4005 344 94 Leon Denebola)
(5975 288 55 Ophi))
(3 ( 46 333 88 Pegs Algenib)
( 362 -244 31 Ceti)
( 490 338 99 Pisc)
( 566 -375 52 Ceti)
( 621 462 6 Arie)
( 764 -78 68 Ceti Mira)
( 900 64 86 Ceti)
(1007 84 92 Ceti)
(1243 -230 23 Erid)
(1328 -314 34 Erid)
(1495 432 74 Taur)
(1496 356 78 Taur)
(1618 154 1 Orio)
(1644 52 8 Orio)
(1723 -119 67 Erid)
(1755 -371 5 Leps)
(1779 -158 20 Orio)
(1817 -57 28 Orio)
(1843 -474 9 Leps)
(1860 -8 34 Orio)
(1868 -407 11 Leps)
(1875 225 39 Orio)
(1880 -136 44 Orio)
(1887 480 123 Taur)
(1948 -338 14 Leps)
(2274 296 31 Gemi)
(2460 380 54 Gemi))
(4 (2470 504 55 Gemi)
(2513 193 3 CMin)
(2967 154 11 Hyda)
(3016 144 16 Hyda)
(3424 393 30 Leon)
(3496 463 41 Leon Algieba)
(3668 -357 nu Hyda)
(3805 479 68 Leon)
(3806 364 10 Leon)
(4124 -502 2 Corv)
(4157 -387 4 Corv)
(4236 -363 7 Corv)
(4304 -21 29 Virg)
(4384 90 43 Virg)
(4421 262 47 Virg)
(4606 -2 79 Virg)
(4721 430 8 Boot)
(5037 -356 9 Libr)
(5186 -205 27 Libr)
(5344 153 24 Serp)
(5357 358 28 Serp)
(5373 -71 32 Serp)
(5430 -508 7 Scor)
(5459 -445 8 Scor)
(5513 -78 1 Ophi)
(5536 -101 2 Ophi)
(5609 494 27 Herc)
(5641 -236 13 Ophi)
(5828 -355 35 Ophi)
(5860 330 64 Herc)
(5984 -349 55 Serp)
(6047 63 62 Ophi)
(6107 -222 64 Ophi)
(6159 217 72 Ophi)
(6236 -66 58 Serp)
(6439 -483 37 Sgtr)
(6490 312 17 Aqil)
(6491 -115 16 Aqil)
(6507 -482 41 Sgtr)
(6602 66 30 Aqil)
(6721 236 50 Aqil)
(6794 437 12 Sgte)
(6862 -25 65 Aqil)
(6914 -344 9 Capr)
(7014 324 6 Dlph)
(7318 -137 22 Aqar)
(7391 214 8 Pegs)
(7404 -377 49 Capr)
(7513 -18 34 Aqar)
(7539 130 26 Pegs)
(7644 -12 55 Aqar)
(7717 235 42 Pegs)
(7790 -372 76 Aqar)
(7849 334 54 Pegs Markab)
( 1 -143 33 Pisc)
( 54 447 89 Pegs)
( 54 -443 7 Ceti)
( 82 -214 8 Ceti)
( 223 -254 17 Ceti)
( 248 160 63 Pisc)
( 273 -38 20 Ceti)
( 329 167 71 Pisc)
( 376 467 84 Pisc)
( 450 -198 45 Ceti)
( 548 113 106 Pisc)
( 570 197 110 Pisc)
( 595 -255 53 Ceti)
( 606 -247 55 Ceti)
( 615 428 5 Arie)
( 617 61 14 Pisc)
( 656 -491 59 Ceti)
( 665 52 113 Pisc)
( 727 191 65 Ceti)
( 803 -290 72 Ceti)
( 813 182 73 Ceti)
( 838 -357 76 Ceti)
( 878 -2 82 Ceti)
( 907 -340 89 Ceti)
( 908 221 87 Ceti)
( 913 -432 1 Erid)
( 947 -487 2 Erid)
( 976 -212 3 Erid)
( 992 194 91 Ceti)
(1058 440 57 Arie)
(1076 470 58 Arie)
(1087 -209 13 Erid)
(1104 68 96 Ceti)
(1110 -503 16 Erid)
(1135 198 1 Taur)
(1148 214 2 Taur)
(1168 287 5 Taur)
(1170 -123 17 Erid)
(1185 -223 18 Erid)
(1191 -500 19 Erid)
(1205 2 10 Taur)
(1260 -283 26 Erid)
(1304 -74 32 Erid)
(1338 278 35 Taur)
(1353 130 38 Taur)
(1358 497 37 Taur)
(1405 -162 38 Erid)
(1414 205 47 Taur)
(1423 197 49 Taur)
(1426 -178 40 Erid)
(1430 463 50 Taur)
(1446 350 54 Taur)
(1463 394 61 Taur)
(1470 392 64 Taur)
(1476 502 65 Taur)
(1477 403 68 Taur)
(1483 350 71 Taur)
(1485 330 73 Taur)
(1495 358 77 Taur)
(1507 364 )
(1518 -6 45 Erid)
(1526 333 86 Taur)
(1537 226 88 Taur)
(1544 -81 48 Erid)
(1551 280 90 Taur)
(1556 358 92 Taur)
(1557 -330 53 Erid)
(1571 -452 54 Erid)
(1596 -78 57 Erid)
(1622 199 2 Orio)
(1626 124 3 Orio)
(1638 -128 61 Erid)
(1646 228 7 Orio)
(1654 304 9 Orio)
(1669 36 10 Orio)
(1680 -289 64 Erid)
(1687 -167 65 Erid)
(1690 -460 )
(1690 488 102 Taur)
(1700 347 11 Orio)
(1729 352 15 Orio)
(1732 -202 69 Erid)
(1750 -273 3 Leps)
(1753 63 17 Orio)
(1756 -297 4 Leps)
(1792 -302 6 Leps)
(1799 -486 )
(1801 -11 22 Orio)
(1807 79 23 Orio)
(1816 -180 29 Orio)
(1818 40 25 Orio)
(1830 497 114 Taur)
(1830 69 30 Orio)
(1851 134 32 Orio)
(1857 421 119 Taur)
(1861 -168 36 Orio)
(1874 214 37 Orio)
(1878 -138 )
(1880 -112 42 Orio)
(1885 210 40 Orio)
(1899 -60 48 Orio)
(1900 93 47 Orio)
(1900 -165 49 Orio)
(1909 375 126 Taur)
(1936 -511 13 Leps)
(1957 287 134 Taur)
(1974 -475 15 Leps)
(1982 461 54 Orio)
(2002 -323 16 Leps)
(2020 -70 )
(2030 220 61 Orio)
(2032 -241 3 Mono)
(2037 458 62 Orio)
(2057 -340 18 Leps)
(2059 336 67 Orio)
(2084 368 69 Orio)
(2084 324 70 Orio)
(2105 -142 5 Mono)
(2112 -311 )
(2153 106 8 Mono)
(2179 462 18 Gemi)
(2179 -107 10 Mono)
(2184 -159 11 Mono)
(2204 168 13 Mono)
(2232 -436 7 CMaj)
(2239 -413 8 CMaj)
(2245 -320 )
(2250 227 15 Mono)
(2266 303 30 Gemi)
(2291 57 18 Mono)
(2327 303 38 Gemi)
(2328 -457 15 CMaj)
(2330 -271 14 CMaj)
(2340 -456 19 CMaj)
(2342 -385 20 CMaj)
(2378 -93 19 Mono)
(2379 471 43 Gemi)
(2385 -352 23 CMaj)
(2428 -8 22 Mono)
(2491 -429 )
(2519 208 4 CMin)
(2527 278 6 CMin)
(2559 -503 )
(2597 -212 26 Mono)
(2704 -412 )
(2709 -25 28 Mono)
(2714 60 )
(2751 -61 29 Mono)
(2757 -431 16 Pupp)
(2768 -288 19 Pupp)
(2794 216 17 Canc)
(2848 -82 )
(2915 138 4 Hyda)
(2921 84 5 Hyda)
(2942 -355 9 Hyda)
(2944 497 43 Canc)
(2947 85 7 Hyda)
(2951 -156 )
(2953 421 47 Canc)
(2968 -300 12 Hyda)
(2976 141 13 Hyda)
(3032 279 65 Canc)
(3124 62 22 Hyda)
(3157 -263 26 Hyda)
(3161 -208 27 Hyda)
(3209 -53 31 Hyda)
(3225 -17 32 Hyda)
(3261 116 )
(3270 -16 35 Hyda)
(3274 -316 38 Hyda)
(3276 236 14 Leon)
(3338 -327 39 Hyda)
(3385 194 29 Leon)
(3415 -286 40 Hyda)
(3428 239 31 Leon)
(3429 3 15 Sext)
(3446 -270 41 Hyda)
(3495 455 40 Leon)
(3534 -372 42 Hyda)
(3557 -3 30 Sext)
(3570 223 47 Leon)
(3726 -404 al Crat)
(3736 -44 61 Leon)
(3738 471 60 Leon)
(3754 179 63 Leon)
(3793 -507 11 Crat)
(3821 -71 74 Leon)
(3836 -324 12 Crat)
(3846 150 77 Leon)
(3861 252 78 Leon)
(3868 -390 15 Crat)
(3935 -211 21 Crat)
(3936 -6 91 Leon)
(3981 -405 27 Crat)
(3986 161 3 Virg)
(3998 473 93 Leon)
(4013 53 5 Virg)
(4072 163 8 Virg)
(4097 211 9 Virg)
(4180 -3 15 Virg)
(4185 418 11 Coma)
(4249 -356 8 Corv)
(4290 -170 26 Virg)
(4305 245 30 Virg)
(4376 -205 40 Virg)
(4403 409 36 Coma)
(4465 -114 51 Virg)
(4466 411 42 Coma)
(4512 -404 61 Virg)
(4563 -352 69 Virg)
(4590 -131 74 Virg)
(4603 95 78 Virg)
(4679 409 4 Boot)
(4691 371 5 Boot)
(4759 46 93 Virg)
(4820 66 )
(4822 -223 98 Virg)
(4840 -126 99 Virg)
(4857 -294 100 Virg)
(4864 382 20 Boot)
(4910 -41 105 Virg)
(4984 383 29 Boot)
(4986 322 30 Boot)
(4994 -119 107 Virg)
(5009 396 35 Boot)
(5013 53 109 Virg)
(5045 444 37 Boot)
(5074 -90 16 Libr)
(5108 57 110 Virg)
(5157 -442 24 Libr)
(5283 -221 37 Libr)
(5290 -329 38 Libr)
(5291 247 13 Serp)
(5326 -440 43 Libr)
(5331 455 21 Serp)
(5357 175 27 Serp)
(5372 420 35 Serp)
(5381 109 37 Serp)
(5387 484 38 Serp)
(5394 -374 46 Libr)
(5415 364 41 Serp)
(5419 -318 48 Libr)
(5455 -253 xi Scor)
(5467 -464 9 Scor)
(5470 -469 10 Scor)
(5497 -437 14 Scor)
(5499 -223 15 Scor)
(5558 29 50 Serp)
(5561 441 20 Herc)
(5565 -451 4 Ophi)
(5580 325 24 Herc)
(5582 -415 7 Ophi)
(5589 -186 3 Ophi)
(5606 -373 8 Ophi)
(5609 50 10 Ophi)
(5610 -484 9 Ophi)
(5620 266 29 Herc)
(5713 -241 20 Ophi)
(5742 235 25 Ophi)
(5763 217 27 Ophi)
(5807 293 60 Herc)
(5868 -8 41 Ophi)
(5888 -478 40 Ophi)
(5889 -290 53 Serp)
(5924 -114 )
(5925 96 49 Ophi)
(5987 -183 57 Ophi)
(6006 -292 56 Serp)
(6016 -492 58 Ophi)
(6117 -84 57 Serp)
(6117 99 66 Ophi)
(6119 381 93 Herc)
(6119 67 67 Ophi)
(6125 30 68 Ophi)
(6146 57 70 Ophi)
(6158 198 71 Ophi)
(6170 473 102 Herc)
(6188 -480 13 Sgtr)
(6234 76 74 Ophi)
(6235 499 106 Herc)
(6247 -204 xi Scut)
(6254 -469 21 Sgtr)
(6255 494 109 Herc)
(6278 -333 ga Scut)
(6313 -189 al Scut)
(6379 465 110 Herc)
(6382 -110 be Scut)
(6386 411 111 Herc)
(6436 93 63 Serp)
(6457 340 13 Aqil)
(6465 -134 12 Aqil)
(6478 -498 39 Sgtr)
(6553 483 1 Vulp)
(6576 -410 44 Sgtr)
(6576 -368 46 Sgtr)
(6607 3 32 Aqil)
(6651 163 38 Aqil)
(6657 445 9 Vulp)
(6665 -35 41 Aqil)
(6688 405 5 Sgte)
(6693 393 6 Sgte)
(6730 416 7 Sgte)
(6739 430 8 Sgte)
(6755 17 55 Aqil)
(6766 187 59 Aqil)
(6772 140 60 Aqil)
(6882 339 67 Aqil)
(6896 -292 5 Capr)
(6898 -292 6 Capr)
(6913 -297 8 Capr)
(6958 -413 11 Capr)
(6988 250 2 Dlph)
(7001 326 4 Dlph)
(7015 -33 71 Aqil)
(7020 475 29 Vulp)
(7026 354 9 Dlph)
(7047 335 11 Dlph)
(7066 359 12 Dlph)
(7067 -225 2 Aqar)
(7068 -123 3 Aqar)
(7096 -213 6 Aqar)
(7161 -461 22 Capr)
(7170 -401 23 Capr)
(7192 -268 13 Aqar)
(7199 222 5 Equl)
(7223 219 7 Equl)
(7230 110 8 Equl)
(7263 -393 32 Capr)
(7267 441 1 Pegs)
(7299 -506 36 Capr)
(7347 -453 39 Capr)
(7353 -189 23 Aqar)
(7365 -390 40 Capr)
(7379 -440 43 Capr)
(7394 384 9 Pegs)
(7499 -60 31 Aqar)
(7513 104 22 Pegs)
(7515 -327 33 Aqar)
(7575 -189 43 Aqar)
(7603 -43 48 Aqar)
(7604 266 31 Pegs)
(7624 20 52 Aqar)
(7639 96 35 Pegs)
(7654 -255 57 Aqar)
(7681 -14 62 Aqar)
(7727 -440 66 Aqar)
(7747 266 46 Pegs)
(7761 -321 71 Aqar)
(7779 -185 73 Aqar)
(7795 189 50 Pegs)
(7844 75 4 Pisc)
(7862 202 55 Pegs)
(7874 -494 88 Aqar)
(7903 -150 90 Aqar)
(7911 -219 91 Aqar)
(7919 62 6 Pisc)
(7923 -222 93 Aqar)
(7952 -470 98 Aqar)
(7969 -482 99 Aqar)
(7975 16 8 Pisc)
(7981 133 10 Pisc)
(7988 278 70 Pegs)
(8010 -489 101 Aqar)
(8049 116 17 Pisc)
(8059 -418 104 Aqar)
(8061 28 18 Pisc)
(8064 -344 105 Aqar)
(8159 144 28 Pisc)
(8174 -149 30 Pisc)
(8188 -407 2 Ceti)))))
| 13,192 | Common Lisp | .lisp | 475 | 20.842105 | 156 | 0.487805 | josrr/guerra-espacial | 1 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 1272e60234c204505a224ad677be792ee5ec930a9af385065549d9da9e2cf2b9 | 25,083 | [
-1
] |
25,084 | estrella.lisp | josrr_guerra-espacial/estrella.lisp | (in-package #:guerra-espacial)
(defun carga-estrellas (lista)
(mapcan (lambda (grupo)
(mapcar (lambda (e)
(list :x (- *ancho-mapa-estelar* (first e))
:y (+ 511 (- (second e)))
:nombre (fourth e)
:constelacion (fifth e)
:magnitud (car grupo)))
(cdr grupo)))
lista))
(defun estrellas-max-x (estrellas)
(apply #'max (mapcar (lambda (e) (getf e :x)) estrellas)))
(defun dibuja-estrellas (pane)
(with-bounding-rectangle* (x0 y0 x1 y1) (sheet-region pane)
(labels ((dibuja-estrella (x y m color)
(let ((r (- (+ 6 (random 1.125)) m))
(c (* 0.5 color)))
(draw-point* pane x y :ink (clim:make-rgb-color (* 0.4 c) c c) :line-thickness (* 2.0 r))
(draw-point* pane x y :ink (clim:make-rgb-color (* 0.4 color) color color) :line-thickness (* 1.0 r)))))
(with-slots (y fondo estrellas) pane
(draw-rectangle* pane x0 y0 x1 y1 :filled t :ink fondo)
(let ((x (espacio-x pane)))
(when (or (> (+ x x1) *max-x-mapa-estelar*) (< (- *max-x-mapa-estelar* x) x1))
(loop with inicio-x = (- *max-x-mapa-estelar* x)
with borde-x = (- x1 inicio-x)
for punto in (remove-if (lambda (e) (> (getf e :x) borde-x)) (espacio-estrellas pane))
initially (draw-line* pane inicio-x 0 inicio-x y1 :ink +gray5+ :line-thickness 1)
do (dibuja-estrella (+ (getf punto :x) inicio-x)
(getf punto :y)
(getf punto :magnitud)
(/ (- 8.0 (getf punto :magnitud)) 8.0))))
(loop with limite-derecho = (+ x x1)
for punto in (remove-if (lambda (e)
(let ((e-x (getf e :x)))
(or (> e-x limite-derecho) (< e-x x))))
(espacio-estrellas pane))
do (dibuja-estrella (- (getf punto :x) x)
(getf punto :y)
(getf punto :magnitud)
(/ (- 8.0 (getf punto :magnitud)) 8.0)))
(let ((nx (- x *desp-x*)))
(setf (espacio-x pane) (if (minusp nx) (+ nx *max-x-mapa-estelar*) nx))))))))
(defun dibuja-estrella (pane x y)
(let ((r (random 3)))
(draw-point* pane x y :ink +green+ :line-thickness (+ 22 (* 6 r)))
(draw-point* pane x y :ink +cyan+ :line-thickness (+ 20 (* 4 r)))
(draw-point* pane x y :ink +yellow2+ :line-thickness (+ 18 (* 3 r)))
(draw-point* pane x y :ink +white+ :line-thickness (+ 16 r))))
(defun dibuja-estrella-% (pane x y)
(let ((dx (- (random 30) 20))
(dy (- (random 30) 20)))
(draw-line* pane (- x dx) (- y dy) (+ x dx) (+ y dy) :line-thickness 3 :ink +yellow+)
(draw-line* pane (- x dx) (- y dy) (+ x dx) (+ y dy) :line-thickness 2 :ink +light-sky-blue+)))
| 3,092 | Common Lisp | .lisp | 54 | 41.814815 | 121 | 0.47247 | josrr/guerra-espacial | 1 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 18e8f6e63fd18f467070ec8b943f53998c32decf0fbf8ad177cf802214eff8c5 | 25,084 | [
-1
] |
25,085 | presentacion.lisp | josrr_guerra-espacial/presentacion.lisp | (in-package #:guerra-espacial)
(defparameter *portada* '#("****************************************************************"
"****************************************************************"
"****************************************************************"
"*****00000**1***1**22222**3333***4444****555********************"
"*****0******1***1**2******3***3**4***4**5***5*******************"
"*****0******1***1**2******3***3**4***4**5***5*******************"
"*****00000**1***1**2222***3333***4444***55555*******************"
"*****0***0**1***1**2******3**3***4**4***5***5*******************"
"*****0***0**1***1**2******3**3***4**4***5***5*******************"
"*****00000***111***22222**3**3***4**4***5***5*******************"
"****************************************************************"
"****************************************************************"
"*****66666***777***8888****999****aaa***bbbbb***ccc***d*********"
"*****6******7***7**8***8**9***9**a***a****b****c***c**d*********"
"*****6******7******8***8**9***9**a********b****c***c**d*********"
"*****6666****777***8888***99999**a********b****ccccc**d*********"
"*****6**********7**8******9***9**a********b****c***c**d*********"
"*****6******7***7**8******9***9**a***a****b****c***c**d*********"
"*****66666***777***8******9***9***aaa***bbbbb**c***c**ddddd*****"
"****************************************************************"
"****************************************************************"
"****************************************************************"
"****************************************************************"
"****************************************************************"
"****************************************************************"
"****************************************************************"
"****************************************************************"
"****************************************************************"
"****************************************************************"
"*eee************************************************************"
"*e*e*ee**eee*ee*****e*e*e*eee*ee**eee***************************"
"*e*e***e*e*****e****e*e*e*e*e***e*e*****************************"
"*eee*eee*e***eee**e*e*e*e*eee*eee*e*****************************"
"*e***e*e*e***e*e**e*e*e*e***e*e*e*e*****************************"
"*e***eee*e***eee**eee*eee*eee*eee*e*****************************"
"****************************************************************"
"****************************************************************"
"*eee*eee*eee*eee*e*eee*eee*ee***eee*e*e*ee**e*eee*e*e*e*eee*eee*"
"*e*e*e***e*e*e***e*e*e*e*e***e**e***e*e***e*e*e*e*e*e*e*e*e*e***"
"*eee*e***eee*eee*e*e*e*e*e*eee**e***e*e*eee*e*eee*e*e*e*eee*e***"
"*e***e***e*****e*e*e*e*e*e*e*e**e***e*e*e*e*e***e*e*e*e*e***e***"
"*e***e****ee*eee*e*eee*e*e*eee**eee*eee*eee*ee**e*eee*e**ee*e***"
"****************************************************************"
"****************************************************************"
"**e**eee*eee*e**ee**********************************************"
"*eee*e*e*e***e****e*********************************************"
"**e**eee*e***e**eee*********************************************"
"**e**e***e***e**e*e*********************************************"
"**e***ee*eee*ee*eee*********************************************"
"****************************************************************"
"****************************************************************"
"****************************************************************"
"****************************************************************"
"****************************************************************"
"****************************************************************"
"****************************************************************"
"****************************************************************"
"*************************f*f*FFF*FFF**********f*****f*****f*****"
"*************************f*f*F*F*F***********f*f***f*f***f*f****"
"*************************f*f*FFF*F***********f*f***f*f****ff****"
"*************************f*f*F***F***********f*f***f*f***f******"
"**************************f***FF*F***f********f**f**f**f*fff****"
"****************************************************************"
"****************************************************************"))
(defun instrucciones (pane)
(copy-from-pixmap (espacio-pixmap pane) 0 0
(bounding-rectangle-width (sheet-region pane))
(bounding-rectangle-height (sheet-region pane))
pane 0 0))
(defun presentacion (pane)
(loop repeat *ms-num-cuadros* do
(with-bounding-rectangle* (x0 y0 x1 y1) (sheet-region pane)
(climi::with-double-buffering ((pane x0 y0 x1 y1) (wtf))
(declare (ignore wtf))
(sleep (/ *pausa* 2))
(munching-squares pane))))
(let ((pixmap (espacio-pixmap pane))
(ancho (bounding-rectangle-width (sheet-region pane)))
(alto (bounding-rectangle-height (sheet-region pane))))
(loop repeat 16 do
(loop with cuantos double-float = *ms-num-cuadros*
with ancho double-float = (min (/ *ancho-df* cuantos) (/ *alto-df* cuantos))
with ancho/2 double-float = (/ ancho 2.0d0)
for i from 0 below *ms-num-cuadros* and x from ancho/2 by ancho
do (loop for j from 0 below *ms-num-cuadros* and y from ancho/2 by ancho
for c = (elt (aref *portada* j) i)
do (draw-circle* pane x y ancho/2 :ink (if (or (char= #\* c)
(< (incf (espacio-num-cuadro pane))
(* 512 (parse-integer (subseq (aref *portada* j) i (1+ i))
:radix 16))))
+darkslategrey+
+cyan+)))))
(copy-to-pixmap pane 0 0 ancho alto pixmap 0 0)
(setf (espacio-animacion-func pane) #'instrucciones)))
| 7,876 | Common Lisp | .lisp | 95 | 57.821053 | 129 | 0.191566 | josrr/guerra-espacial | 1 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | b5ed08b43d10b8b594ca3cda614358de86f37e367ec57c395600a157a75243ad | 25,085 | [
-1
] |
25,086 | guerra-espacial.lisp | josrr_guerra-espacial/guerra-espacial.lisp | (in-package #:guerra-espacial)
(defun anima (frame)
(lambda ()
(loop with pane = (find-pane-named frame 'espacio-pane)
while (bt:with-lock-held ((guesp-bloqueo frame)) (null (espacio-terminar pane)))
initially (presentacion pane)
do (bt:with-lock-held ((guesp-bloqueo frame))
(unless (espacio-terminar pane)
(with-bounding-rectangle* (x0 y0 x1 y1) (sheet-region pane)
(climi::with-double-buffering ((pane x0 y0 x1 y1) (wtf-wtf-wtf))
(declare (ignore wtf-wtf-wtf))
(when (espacio-animacion-func pane)
(funcall (espacio-animacion-func pane) pane))))))
(bt:thread-yield)
(sleep *pausa*))))
(defun inicia ()
(let* ((teclas (make-hash-table))
(frame (make-application-frame 'guerra-espacial
:teclas teclas)))
(mapcar (lambda (nave)
(dolist (op '(:izq :der :empuje :fuego :hiperespacio))
(dolist (tecla (getf (cdr nave) op))
(setf (gethash tecla teclas) (list (car nave) op)))))
*teclas*)
(run-frame-top-level frame)
(when (espacio-pixmap (find-pane-named frame 'espacio-pane))
(clim:deallocate-pixmap (espacio-pixmap (find-pane-named frame 'espacio-pane))))
(let ((hilo (guesp-hilo-animacion frame)))
(when (and hilo (bt:thread-alive-p hilo)
(bt:destroy-thread hilo)))))
:name "Guerra Espacial")
(defun salir ()
#+sbcl (sb-ext:quit)
#+ecl (ext:quit)
#+clisp (ext:exit)
#+ccl (ccl:quit)
#-(or sbcl ecl clisp ccl) (cl-user::quit))
(defun main (&rest arguments)
(declare (ignore arguments))
(let ((hilo (bt:make-thread #'inicia :name "guesp")))
(bt:join-thread hilo)
(unless (find :swank *features*)
(salir))))
(defclass espacio-pane (climi::never-repaint-background-mixin basic-gadget)
((x :initform (- 4096 *ancho*) :accessor espacio-x)
(y :initform 0 :accessor espacio-y)
(fondo :initform +black+
:reader espacio-color-de-fondo)
(pixmap :initform nil :accessor espacio-pixmap)
(estrellas :initform *estrellas* :reader espacio-estrellas)
(objetos :initform (carga-naves *naves*) :accessor espacio-objs)
(num-cuadro :initform 1 :accessor espacio-num-cuadro)
(animacion-func :initarg :animacion-func :initform nil :accessor espacio-animacion-func)
(datos :initform (list) :accessor espacio-datos)
(jugando :initform nil :accessor espacio-jugando)
(terminar :initform nil :accessor espacio-terminar)))
(defmethod initialize-instance :after ((pane espacio-pane) &key contents)
(declare (ignore contents))
t)
(defmethod compose-space ((pane espacio-pane) &key width height)
(declare (ignore width height))
(make-space-requirement :min-width *ancho*
:min-height *alto*
:width *ancho*
:height *alto*
:max-width *ancho*
:max-height *alto*))
(define-application-frame guerra-espacial ()
((teclas :initarg :teclas :initform nil)
(hilo-animacion :initform (bt:make-lock) :accessor guesp-hilo-animacion)
(bloqueo :initform (bt:make-lock "Bloqueo para el frame") :accessor guesp-bloqueo))
(:panes (espacio-pane (make-pane 'espacio-pane
:animacion-func #'spacewar!)))
(:layouts (:default espacio-pane))
(:menu-bar t))
(defmethod run-frame-top-level :before (frame &key &allow-other-keys)
(let* ((pane (find-pane-named frame 'espacio-pane))
(pixmap (allocate-pixmap pane
(bounding-rectangle-width (sheet-region pane))
(bounding-rectangle-height (sheet-region pane)))))
(setf (espacio-pixmap pane) pixmap)
(setf (slot-value pixmap 'medium) (make-medium (port pane) pixmap)))
(setf (guesp-hilo-animacion frame)
(bt:make-thread (anima frame) :name "Animación")))
(defmethod handle-event ((gadget espacio-pane) (evento key-press-event))
(when *application-frame*
(with-slots (escenario teclas) *application-frame*
(let* ((tecla (keyboard-event-key-name evento))
(accion (gethash tecla teclas)))
(if accion
(agrega-control-nave gadget (car accion) (cadr accion))
(case tecla
((:|Q| :|q|) (when (espacio-jugando gadget)
(execute-frame-command *application-frame* `(com-salir))))
((:|N| :|n|) (execute-frame-command *application-frame* `(com-reiniciar)))
(t (unless (espacio-jugando gadget)
(execute-frame-command *application-frame* `(com-guerra-espacial))))))))))
(defmethod handle-event ((gadget espacio-pane) (evento key-release-event))
(when *application-frame*
(with-slots (escenario teclas) *application-frame*
(let* ((tecla (keyboard-event-key-name evento))
(accion (gethash tecla teclas)))
(when accion
(quita-control-nave gadget (car accion) (cadr accion)))))))
;;;; Comandos
(define-guerra-espacial-command (com-guerra-espacial :name "Guerra Espacial" :menu t)
()
(let ((espacio (find-pane-named *application-frame* 'espacio-pane)))
(bt:with-lock-held ((guesp-bloqueo *application-frame*))
(setf (espacio-jugando espacio) t
(espacio-animacion-func espacio) #'spacewar!
(espacio-num-cuadro espacio) 1))))
(define-guerra-espacial-command (com-minskytron :name "Minskytron" :menu t)
()
(let ((espacio (find-pane-named *application-frame* 'espacio-pane)))
(bt:with-lock-held ((guesp-bloqueo *application-frame*))
(setf (espacio-jugando espacio) t
(espacio-animacion-func espacio) #'minskytron
(espacio-num-cuadro espacio) 1
(espacio-datos espacio) nil)
(draw-rectangle* (espacio-pixmap espacio) 0 0
(bounding-rectangle-width (sheet-region espacio))
(bounding-rectangle-height (sheet-region espacio))
:ink +black+))))
(define-guerra-espacial-command (com-munching-squares :name "Munching Squares" :menu t)
()
(let ((espacio (find-pane-named *application-frame* 'espacio-pane)))
(bt:with-lock-held ((guesp-bloqueo *application-frame*))
(setf (espacio-jugando espacio) t
(espacio-animacion-func espacio) #'munching-squares
(espacio-num-cuadro espacio) 1))))
(define-guerra-espacial-command (com-reiniciar :name "Reiniciar" :menu t)
()
(let ((espacio (find-pane-named *application-frame* 'espacio-pane)))
(bt:with-lock-held ((guesp-bloqueo *application-frame*))
(setf (espacio-jugando espacio) t
(espacio-objs espacio) (carga-naves *naves*)
(espacio-num-cuadro espacio) 1
(espacio-datos espacio) nil))))
(define-guerra-espacial-command (com-salir :name "Salir" :menu t)
()
(bt:with-lock-held ((guesp-bloqueo *application-frame*))
(let ((espacio (find-pane-named *application-frame* 'espacio-pane)))
(setf (espacio-terminar espacio) t)
(frame-exit *application-frame*))))
(defun guerra-espacial-entry-point ()
(apply 'main *command-line-arguments*))
| 7,317 | Common Lisp | .lisp | 147 | 40.666667 | 93 | 0.627887 | josrr/guerra-espacial | 1 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | ac3e8afdb50a80fa67a0250bd5aa1c1639d55a7b1be8629981fef567014370eb | 25,086 | [
-1
] |
25,087 | genexe.lisp | josrr_guerra-espacial/genexe.lisp | ;; -*- coding: utf-8-unix; -*-
(in-package #:common-lisp-user)
;;(ql:quickload "cffi-grovel")
(asdf:make :guerra-espacial)
| 123 | Common Lisp | .lisp | 4 | 29.75 | 31 | 0.672269 | josrr/guerra-espacial | 1 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | d4df04270ea7c6f4dbd96fc68ab2be75497b6871b0b6b80570ad54c32bc0efa1 | 25,087 | [
-1
] |
25,088 | guerra-espacial.asd | josrr_guerra-espacial/guerra-espacial.asd | ;; -*- coding: utf-8-unix; -*-
;;;; Copyright (c) 2018 José Ronquillo Rivera <[email protected]>
;;;; This file is part of guerra-espacial.
;;;;
;;;; guerra-espacial 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.
;;;;
;;;; guerra-espacial 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 guerra-espacial. If not, see <http://www.gnu.org/licenses/>.
(asdf:defsystem #:guerra-espacial
:defsystem-depends-on (:deploy)
:description "Spacewar! clone"
:author "José Miguel Ronquillo Rivera <[email protected]>"
:serial t
:license "GPL Ver. 3"
:version "0.0.2"
:build-operation "deploy-op"
:build-pathname #P"guerra-espacial"
:entry-point "guerra-espacial:guerra-espacial-entry-point"
:depends-on (#:bordeaux-threads #:mcclim)
:components ((:file "paquetes")
(:file "parametros")
(:file "nave")
(:file "estrella")
(:file "datos-naves")
(:file "datos-estrellas")
(:file "animaciones")
(:file "presentacion")
(:file "guerra-espacial")))
| 1,547 | Common Lisp | .asd | 36 | 37.916667 | 77 | 0.664234 | josrr/guerra-espacial | 1 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 0363c613418ce3b2c800c06733a288297bc61a14bf3d9d50eb76ecd8e5abbff6 | 25,088 | [
-1
] |
25,115 | main.lisp | Subtodempen_Huffman-Coding-Compression/main.lisp | ; read file
(defun readFile (filename)
(with-open-file (stream filename :if-does-not-exist nil)
(if (not stream)
nil
(loop for line = (read-line stream nil)
while line
collect (coerce line 'list)))))
(defun formatFileData (matrix)
"Takes in a matrix and returns a list"
(apply #'append matrix))
; create priorety queue
(defun makeEmptyPriorityQueue ()
nil)
(defun makePriorityQueue (aLst)
(sort aLst #'< :key #'cdr))
(defun enQueue (pQueue val)
(makePriorityQueue (append pQueue (list val)))) ; make faster
(defun deQueue (pQueue)
(cdr pQueue))
(defun peek (pQueue)
(car pQueue))
;create biunary tree
(defun makeBinaryTree (root n1 n2)
(list root n1 n2))
; create alist freq table
(defun fillFreqTable (str)
(let ((freqTable nil) (val nil))
(loop for c in str do
(setf val (assoc c freqTable))
(if val
(setf (cdr (assoc c freqTable)) (1+ (cdr val))) ; the character is in the alist so we append the freq by one
(setf freqTable (enQueue freqTable (cons c 1))))) ; if val is null than the character c is not in the alist so add it with a freq of one
freqTable))
; create huffman tree
(defun createHuffmanTree (freqTable)
(if (= (length freqTable) 1)
(car freqTable)
(createHuffmanTree
(enQueue (cddr freqTable)
(let ((node1 (pop freqTable)) (node2 (pop freqTable)))
(cons
(makeBinaryTree nil node1 node2)
(+ (cdr node1) (cdr node2))))))))
(defun dottedListP (lst)
(not (listp (cdr lst))))
(defun cleanHuffmanTree (tree)
(cond
((atom tree) tree)
((dottedListP tree) (cleanHuffmanTree (car tree)))
((listP tree) (mapcar #'cleanHuffmanTree tree))
(t tree)))
; iterate through file and encode it with the huffman tree
(defun huffmanEncodeChar (tree char &optional (path nil) (i 0))
(let ((c1 (nth (+ 1 (* i 2)) tree)) (c2 (nth (+ 2 (* i 2)) tree)))
(or
(cond
((null c1) nil)
((listp c1) (huffmanEncodeChar c1 char (append path (list 1))))
((char= c1 char) (append path (list 1)))
(t nil))
(cond
((null c2) nil)
((listp c2) (huffmanEncodeChar c2 char (append path (list 0))))
((char= c2 char) (append path (list 0)))
(t nil))
)))
(defun huffmanEncodeString (tree str)
(let ((path nil))
(loop for c in str do
(push (huffmanEncodeChar tree c) path))
(reverse path)))
; write new encoded data to file
; reverse to decode
(defun huffmanDecodeBin (tree binList)
"decodes one char from a huffman encoded binary"
(let ((treeI 0) (binI 0))
(if (= (nth binI binList) 1)
(setf treeI (+ 1 (* treeI 2)))
(setf treeI (+ 2 (* treeI 2))))
(if (listp (nth treeI tree))
(huffmanDecodeBin (nth treeI tree) (cdr binList))
(nth treeI tree))))
(defun huffmanDecodeBinList (tree binMatrix)
(let ((strResult nil))
(loop for b in binMatrix do
(push (huffmanDecodeBin tree b) strResult))
(reverse strResult)))
(defun writeFile (fName contents)
(with-open-file (stream fName
:direction :output
:if-exists :supersede
:if-does-not-exist :create)
(format stream "~a~%" contents)))
(print "What is the file you want to compress?")
(force-output)
(defvar *fileData*
(formatFileData
(readFile
(read-line))))
(defvar *tree*
(cleanHuffmanTree
(createHuffmanTree
(fillFreqtable
*fileData*))))
(defvar *bin* (huffmanEncodeString *tree* *fileData*))
(print "What is the new file name?")
(force-output)
(writeFile (read-line) (append *tree* *bin*))
(print (readFile (read-line)))
;(print (huffmanDecodeBinList *tree* *bin*))
| 3,794 | Common Lisp | .lisp | 111 | 28.567568 | 148 | 0.635789 | Subtodempen/Huffman-Coding-Compression | 1 | 0 | 0 | GPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 7befdec677ccbf2dd35b5be98f4a97a8fd3d29174bfc995b85b841e689d31636 | 25,115 | [
-1
] |
25,132 | karen.lisp | tamamu_karen/src/karen.lisp | (in-package :cl-user)
(defpackage karen
(:use :cl))
(in-package :karen)
;; blah blah blah.
| 94 | Common Lisp | .lisp | 5 | 17.2 | 21 | 0.693182 | tamamu/karen | 1 | 0 | 0 | MPL-2.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 6b0c8a346d388890f8e9f415f235112df9fc0242fb23d73865a76c743af982f5 | 25,132 | [
-1
] |
25,133 | karen.lisp | tamamu_karen/tests/karen.lisp | (in-package :cl-user)
(defpackage karen-test
(:use :cl
:karen
:prove))
(in-package :karen-test)
;; NOTE: To run this test file, execute `(asdf:test-system :karen)' in your Lisp.
(plan nil)
;; blah blah blah.
(finalize)
| 241 | Common Lisp | .lisp | 10 | 20.9 | 81 | 0.665198 | tamamu/karen | 1 | 0 | 0 | MPL-2.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | c1fcb295030e725e07e0d3c979cd95e54c640493b82e50c3804117be58d3655c | 25,133 | [
-1
] |
25,134 | karen-test.asd | tamamu_karen/karen-test.asd | #|
This file is a part of karen project.
Copyright (c) 2017 Eddie ([email protected])
|#
(in-package :cl-user)
(defpackage karen-test-asd
(:use :cl :asdf))
(in-package :karen-test-asd)
(defsystem karen-test
:author "Eddie"
:license "MPL 2.0"
:depends-on (:karen
:prove)
:components ((:module "tests"
:components
((:test-file "karen"))))
:description "Test system for karen"
:defsystem-depends-on (:prove-asdf)
:perform (test-op :after (op c)
(funcall (intern #.(string :run-test-system) :prove-asdf) c)
(asdf:clear-system c)))
| 641 | Common Lisp | .asd | 21 | 24.285714 | 80 | 0.602917 | tamamu/karen | 1 | 0 | 0 | MPL-2.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | c2bacace8e643b2b4edb03bd1504ab84c7e5dd00253d33df8e23ff4d6e130a36 | 25,134 | [
-1
] |
25,135 | karen.asd | tamamu_karen/karen.asd | #|
This file is a part of karen project.
Copyright (c) 2017 Eddie ([email protected])
|#
#|
Author: Eddie ([email protected])
|#
(in-package :cl-user)
(defpackage karen-asd
(:use :cl :asdf))
(in-package :karen-asd)
(defsystem karen
:version "0.1"
:author "Eddie"
:license "MPL 2.0"
:depends-on (:cl-annot
:cl-opengl
:cl-glut
:alexandria
:uiop
:lparallel
:trivial-features)
:components ((:module "src"
:components
((:file "karen"))))
:description "Experimental web browser engine implemented in Common Lisp"
:long-description
#.(with-open-file (stream (merge-pathnames
#p"README.markdown"
(or *load-pathname* *compile-file-pathname*))
:if-does-not-exist nil
:direction :input)
(when stream
(let ((seq (make-array (file-length stream)
:element-type 'character
:fill-pointer t)))
(setf (fill-pointer seq) (read-sequence seq stream))
seq)))
:in-order-to ((test-op (test-op karen-test))))
| 1,253 | Common Lisp | .asd | 39 | 21.871795 | 75 | 0.527663 | tamamu/karen | 1 | 0 | 0 | MPL-2.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | be9b2118c89fc84f8fd909bb7765a143fd4fa5dd94891b7c3582c2b3fd6c4e56 | 25,135 | [
-1
] |
25,136 | circle.yml | tamamu_karen/circle.yml | machine:
environment:
PATH: ~/.roswell/bin:$PATH
REVIEWDOG_VERSION: 0.9.6
COVERAGE_EXCLUDE: quicklisp/
dependencies:
cache_directories:
- ~/.roswell/
pre:
- sudo apt-get update; sudo apt-get install freeglut3-dev libglew1.5-dev libxmu-dev libxi-dev
- curl -L https://raw.githubusercontent.com/snmsts/roswell/release/scripts/install-for-ci.sh | sh
- ros install sbcl-bin
- ros use sbcl-bin
- ros run -- --version
- ros install qlot
- ros install fukamachi/sblint
- ros install prove
- ros install cl-coveralls
- ros install codex
override:
- curl -fSL https://github.com/haya14busa/reviewdog/releases/download/$REVIEWDOG_VERSION/reviewdog_linux_amd64 -o reviewdog && chmod +x ./reviewdog
post:
- qlot install
- cp ~/.roswell/local-projects/fukamachi/sblint/roswell/sblint.ros ~/.roswell/bin/
test:
override:
- >-
sblint | ./reviewdog -efm="%f:%l:%c: %m" -diff="git diff master" -ci="circle-ci"
- COVERALLS=true qlot exec run-prove karen-test.asd | 1,072 | Common Lisp | .cl | 29 | 31.586207 | 152 | 0.678227 | tamamu/karen | 1 | 0 | 0 | MPL-2.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 298a89e5649ce5e7d3b8ca63c4e13bac7ad3d0776db2440edf79f3309bc1032f | 25,136 | [
-1
] |
25,139 | qlfile | tamamu_karen/qlfile | ql cl-annot :latest
ql cl-opengl :latest
ql alexandria :latest
ql lparallel :latest
ql trivial-features :latest | 115 | Common Lisp | .l | 5 | 21.4 | 27 | 0.801802 | tamamu/karen | 1 | 0 | 0 | MPL-2.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 6cb44e96b5caa144ccc3a016184d8a81d6d8593f6b0e9ca59b5774647940c402 | 25,139 | [
-1
] |
25,142 | level-2.html | tamamu_karen/tests/html/level-2.html | <!DOCTYPE html>
<html>
<body>
<p>JPEG</p>
<img src="../image/test.jpg">
<p>PNG</p>
<img src="../image/test.png">
<p>GIF</p>
<img src="../image/test.gif">
</body>
</html>
| 184 | Common Lisp | .l | 11 | 14.454545 | 31 | 0.560694 | tamamu/karen | 1 | 0 | 0 | MPL-2.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 14c96079be88b0fdd88dac098105d2021dbfae14930165831db5a754d588d487 | 25,142 | [
-1
] |
25,143 | level-3.html | tamamu_karen/tests/html/level-3.html | <!DOCTYPE html>
<html>
<head>
<title>Level-3 - Testing Karen</title>
<link rel="stylesheet" href="../style/level-3.css">
</head>
<body>
<p class="red">Red text</p>
<img id="big-image" src="../image/test.png">
<p>Normal text</p>
<b>Bold text</b>
Direct inner text
</body>
</html>
| 297 | Common Lisp | .l | 14 | 18.928571 | 53 | 0.636042 | tamamu/karen | 1 | 0 | 0 | MPL-2.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | ca274c13a83719d2828231017e9ef5bafff2609d5575ac89bdd7bbd116dbb7da | 25,143 | [
-1
] |
25,158 | informer.lisp | open-rsx_rsb-cl/test/informer.lisp | ;;;; informer.lisp --- Unit tests for informer class.
;;;;
;;;; Copyright (C) 2011-2016 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.test)
(deftestsuite informer-root (root
participant-suite)
()
(:documentation
"Unit tests for the `informer' class."))
(define-basic-participant-test-cases informer
'("/rsbtest/informer/construction"
(:type t)
"/rsbtest/informer/construction")
'("/rsbtest/informer/construction"
(:type t :transports ((:inprocess &inherit)))
"/rsbtest/informer/construction")
'("/rsbtest/informer/construction"
(:type t :transports ((t &inherit) (:inprocess &inherit)))
"/rsbtest/informer/construction")
'("/rsbtest/informer/construction"
(:type t :converters ((t . :foo)))
"/rsbtest/informer/construction")
`("/rsbtest/informer/construction"
(:type t :transform ,#'1+)
"/rsbtest/informer/construction")
`("/rsbtest/informer/construction"
(:type t :parent ,*simple-parent*)
"/rsbtest/informer/construction")
'("/rsbtest/informer/construction"
(:type t :introspection? nil)
"/rsbtest/informer/construction")
'("/rsbtest/informer/construction"
(:type t :introspection? t)
"/rsbtest/informer/construction")
'("inprocess:/rsbtest/informer/construction"
(:type t)
"/rsbtest/informer/construction")
`("inprocess:/rsbtest/informer/construction"
(:type t :error-policy ,#'continue)
"/rsbtest/informer/construction")
`("/rsbtest/informer/construction?foo=bar"
(:type t)
"/rsbtest/informer/construction")
;; No transports => error
'("/rsbtest/informer/construction"
(:type t :transports ((t :enabled nil)))
error))
(addtest (informer-root
:documentation
"Test sending data.")
send/data
(with-participant (informer :informer "/rsbtest/informer/send")
(iter (repeat 100)
(send informer "<foo/>")
(send informer "<bar/>"))))
(addtest (informer-root
:documentation
"Test sending data.")
send/event
(with-participant (informer :informer "/rsbtest/informer/send/event")
(ensure-cases (scope data args
expected-meta-data expected-method expected-timestamps
expected-causes)
`(;; Some invalid cases.
("/rsbtest/informer/send/event" "foo" (:foo foo) ; invalid meta-data item
type-error nil nil nil)
("/rsbtest/informer/send/event" "foo" (:timestamps (:foo 1)) ; invalid timestamp
type-error nil nil nil)
;; These are valid
("/rsbtest/informer/send/event" "foo" ()
() nil () ())
("/rsbtest/informer/send/event" "foo" (:method :bar)
() :bar () ())
("/rsbtest/informer/send/event" "foo" (:foo "baz")
((:foo . "baz")) nil () ())
("/rsbtest/informer/send/event" "foo" (:foo 1)
((:foo . 1)) nil () ())
("/rsbtest/informer/send/event" "foo" (:foo :baz)
((:foo . :baz)) nil () ())
("/rsbtest/informer/send/event" "foo"
(:timestamps (:foo ,(local-time:parse-timestring
"2013-03-27T14:12:32.062533+01:00")))
() nil ((:foo . ,(local-time:parse-timestring
"2013-03-27T14:12:32.062533+01:00"))) ())
("/rsbtest/informer/send/event" "foo" (:causes ((,(uuid:make-null-uuid) . 1)))
() nil () ((,(uuid:make-null-uuid) . 1))))
(let+ (((&flet do-it ()
(apply #'send informer (make-event scope data) args)))
((&flet+ timestamp-entries-equal ((left-key . left-timestamp)
(right-key . right-timestamp))
(and (eq left-key right-key)
(local-time:timestamp= left-timestamp right-timestamp)))))
(case expected-meta-data
(type-error
(ensure-condition 'type-error (do-it)))
(t
(let ((result (do-it)))
(ensure-same (meta-data-alist result) expected-meta-data
:test (rcurry #'set-equal :test #'equal))
(ensure-same (event-method result) expected-method
:test #'eq)
(ensure-same (remove-if
(lambda (name)
(member name *framework-timestamps* :test #'eq))
(timestamp-alist result) :key #'car)
expected-timestamps
:test (rcurry #'set-equal :test #'timestamp-entries-equal))
(ensure-same (event-causes result) expected-causes
:test (rcurry #'set-equal :test #'event-id=)))))))))
(addtest (informer-root
:documentation
"Test the type check employed by the `send' method.")
send/check-type
(with-participant (informer :informer "/rsbtest/informer/send/check-type"
:type 'sequence)
;; In this case, the event cannot be constructed from the payload.
(ensure-condition 'type-error
(send informer 5))
;; In this case, the event is not compatible with the informer's
;; type.
(ensure-condition 'event-type-error
(send informer (make-event "/rsbtest/informer/send/check-type" 5)))
;; The following are compatible.
(send informer '(1 2))
(send informer (make-event "/rsbtest/informer/send/check-type" "bla"))))
(addtest (informer-root
:documentation
"Test the scope check employed by the `send' method.")
send/check-scope
(with-participant (informer :informer "/rsbtest/informer/send/check-scope")
;; Identical scope and subscopes are allowed
(send informer (make-event "/rsbtest/informer/send/check-scope" "foo"))
(send informer (make-event "/rsbtest/informer/send/check-scope/subscope" "foo"))
;; Scope is not identical to or a subscope of the informer's
;; scope.
(ensure-condition 'event-scope-error
(send informer (make-event "/rsbtest/informer/send/wrong-scope" "foo")))))
(addtest (informer-root
:documentation
"Test the \"unchecked\" mode of operation of the `send'
method.")
send/unchecked
(with-participant (informer :informer "/rsbtest/informer/send/unchecked"
:type 'string)
;; Arbitrary scopes should be accepted.
(send informer (make-event "/rsbtest/informer/send/unchecked" "foo")
:unchecked? t)
(send informer (make-event "/rsbtest/informer/send/unchecked/subscope" "foo")
:unchecked? t)
(send informer (make-event "/rsbtest/informer/send/wrong-scope" "foo")
:unchecked? t)
;; Arbitrary data types should accepted.
(send informer (make-event "/rsbtest/informer/send/unchecked" "foo")
:unchecked? t)
(send informer (make-event "/rsbtest/informer/send/unchecked" 1)
:unchecked? t)))
(addtest (informer-root
:documentation
"Test the \"unchecked\" mode of operation of the `send'
method.")
send/no-fill
(with-participant (informer :informer "/rsbtest/informer/send/no-fill")
(let* ((event (make-event "/rsbtest/informer/send/no-fill" "foo"))
(event* (send informer event :no-fill? t)))
(setf (event-origin event) (uuid:make-null-uuid)
(event-sequence-number event) 1234)
(ensure-same (event-origin event*) (event-origin event)
:test #'uuid:uuid=)
(ensure-same (event-sequence-number event*)
(event-sequence-number event)))))
(define-error-hook-test-case (informer :participant? nil)
;; We cannot currently cause the informer case to fail when using
;; inprocess transport. So we just add the error handler without
;; exercising it.
(send informer "foo"))
(addtest (informer-root
:documentation
"Test sequence number generator, especially modular
arithmetic behavior around 2^32.")
sequence-number-generator
(ensure-cases (start expected)
`((0 (0 1 2))
(,(- (ash 1 32) 2) (,(- (ash 1 32) 2) ,(- (ash 1 32) 1) 0 1 2)))
(let ((generator (rsb::make-sequence-number-generator start)))
(iter (for value/generated next (funcall generator))
(for value/expected in expected)
(ensure-same value/generated value/expected
:test #'=)))))
| 8,528 | Common Lisp | .lisp | 190 | 35.710526 | 90 | 0.603326 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 4bbe46bedb66a51db3aae1f1f2218870345400f3184ca4163b576f4f22b0e685 | 25,158 | [
-1
] |
25,159 | random.lisp | open-rsx_rsb-cl/test/random.lisp | ;;;; random.lisp --- Utilities for random testing.
;;;;
;;;; Copyright (C) 2015 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.test)
;;; Generic random utilities
(defun random-boolean (true &key (true-probability .7))
(lambda ()
(when (< (random 1.0) true-probability)
(funcall true))))
(defun random-integer (min max)
(if (= min max)
(constantly min)
(lambda ()
(+ min (random (1+ (- max min)))))))
(defun random-element (sequence)
(curry #'random-elt sequence))
(defun random-sequence (type length element)
(lambda ()
(map-into (make-sequence (funcall type) (funcall length)) element)))
(defparameter *default-random-characters*
(remove-if-not #'alphanumericp (mapcar #'code-char (iota 255))))
(defun random-character (&key (characters *default-random-characters*))
(random-element characters))
(defun random-string (length &key (character (random-character)))
(random-sequence (constantly 'string) length character))
(defun random-list (length element)
(random-sequence (constantly 'list) length element))
(defmacro define-random-instance-maker ((name class) &body slots)
(let+ (((&values initargs keyword-parameters)
(iter (for (name default) :in slots)
(appending (list (make-keyword name) `(funcall ,name)) :into initargs)
(appending (list (list name default)) :into keyword-parameters)
(finally (return (values initargs keyword-parameters))))))
`(defun ,name (&key ,@keyword-parameters)
(lambda () (make-instance ',class ,@initargs)))))
;;; Random scopes
(defparameter *default-random-scope-characters*
(remove-if-not #'scope-component-character?
(mapcar #'code-char (iota 255))))
(defun random-scope-component
(&key
(length (random-integer 1 1))
(character (random-character
:characters *default-random-scope-characters*)))
(random-string length :character character))
(defun random-scope (&key
(length (random-integer 1 1))
(component (random-scope-component)))
(lambda ()
(rsb:make-scope (funcall (random-list length component)))))
;;; Random participants
(defvar *kinds* '(:listener :informer
:local-method :local-server
:remote-method :remote-server))
(defun random-kind (&key (kinds *kinds*))
(random-element kinds))
| 2,473 | Common Lisp | .lisp | 58 | 36.862069 | 86 | 0.661243 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 28737307384c78fec859edf0cc8bb858ad215f531e8c989952785f9be6e73eb2 | 25,159 | [
-1
] |
25,160 | util.lisp | open-rsx_rsb-cl/test/util.lisp | ;;;; util.lisp --- Unit tests for utilities used by the rsb system.
;;;;
;;;; Copyright (C) 2014, 2016 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.test)
(deftestsuite curry/weak-root (root)
()
(:documentation
"Test suite for the `curry/weak' function."))
(addtest (curry/weak-root
:documentation
"Smoke test for the `curry/weak' function.")
smoke
(let+ ((f (rsb::curry/weak #'1+ 1))
((&values result result?) (funcall f)))
(when result? (ensure-same result 2)))
(let+ ((f (rsb::curry/weak #'+ 1))
((&values result result?) (funcall f 2)))
(when result? (ensure-same result 3))))
(macrolet
((define-construction-cases (class)
`(ensure-cases (initargs expected)
`((() missing-required-initarg)
((:interval 1) missing-required-initarg)
((:interval 1 :function ,,'#'+) t)
((:interval 1 :function ,,'#'print :args (list 1 *standard-output*)) t))
(let+ (((&flet do-it ()
(detach (apply #'make-instance ',class initargs)))))
(case expected
(missing-required-initarg
(ensure-condition missing-required-initarg
(do-it)))
(t
(do-it)))))))
(deftestsuite timed-executor-root (root)
()
(:documentation
"Test suite for the `timed-executor' class."))
(addtest (timed-executor-root
:documentation
"Test constructing `timed-executor' instances.")
construction
(define-construction-cases timed-executor))
(deftestsuite timed-executor/weak-root (root)
()
(:documentation
"Test suite for the `timed-executor/weak' class."))
(addtest (timed-executor/weak-root
:documentation
"Test constructing `timed-executor/weak' instances.")
construction
(define-construction-cases timed-executor/weak)))
| 2,136 | Common Lisp | .lisp | 53 | 32.660377 | 108 | 0.558937 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | e6c8086df2a63a10518c1fa831fc7df7efb2e539e65ed720d212c7b5edc3a239 | 25,160 | [
-1
] |
25,161 | event.lisp | open-rsx_rsb-cl/test/event.lisp | ;;;; event.lisp --- Unit tests for the event class.
;;;;
;;;; Copyright (C) 2011, 2012, 2013, 2014, 2015 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.test)
(deftestsuite event-root (root)
()
(:documentation
"Unit tests for the `event' class."))
(addtest (event-root
:documentation
"Test construction of `event' instances.")
construction
(ensure-cases (initargs expected)
`(;; Cannot have an `event' without scope
(() missing-required-initarg)
;; These are OK
((:scope ,(make-scope "/") :data "foo") ("/" "foo" (:create)))
((:scope "/" :data "foo") ("/" "foo" (:create)))
((:scope ("foo" "bar") :data "foo") ("/foo/bar" "foo" (:create)))
((:scope "/baz" :data "bar" :create-timestamp? nil)
("/baz/" "bar" ((not :create))))
((:scope "/baz" :data "bar" :unchecked? t)
("/baz" "bar" (:create)))
((:scope "/" :data "foo" :timestamps (:foo ,(local-time:now)))
("/" "foo" (:create :foo))))
(let+ (((&flet via-make-instance ()
(apply #'make-instance 'event initargs)))
((&flet via-make-event (scope data initargs)
(apply #'make-event scope data initargs))))
(case expected
(missing-required-initarg
(ensure-condition 'missing-required-initarg
(via-make-instance)))
(t
(let+ (((expected-scope expected-payload expected-timestamps)
expected)
((&flet check (event)
(check-event event expected-scope expected-payload)
(dolist (expected-timestamp expected-timestamps)
(typecase expected-timestamp
(keyword
(ensure (typep (timestamp event expected-timestamp)
'local-time:timestamp)))
((cons (eql not) (cons keyword null))
(ensure-null
(timestamp event (second expected-timestamp)))))))))
(unless (getf initargs :unchecked?)
(check (via-make-instance)))
(when-let ((scope (getf initargs :scope))
(data (getf initargs :data)))
(check
(via-make-event
scope data (remove-from-plist initargs :scope :data)))))))))
;; Cannot have an `event' without scope
(ensure-condition 'missing-required-initarg
(make-instance 'event))
(let ((event (make-instance 'event
:scope (make-scope "/")
:data "foo")))
(check-event event "/" "foo")
(ensure (typep (timestamp event :create) 'local-time:timestamp)))
(let ((event (make-instance 'event
:scope (make-scope "/baz")
:data "bar"
:create-timestamp? nil)))
(check-event event "/baz/" "bar")
(ensure-null (timestamp event :create)))
(let ((event (make-instance 'event
:scope (make-scope "/")
:data "foo"
:timestamps `(:foo ,(local-time:now)))))
(check-event event "/" "foo")
(ensure (typep (timestamp event :foo) 'local-time:timestamp))))
(addtest (event-root
:documentation
"Test computation of event sequence numbers.")
id-computation
;; Test some examples. Note that event ids cannot be computed
;; without origin id.
(ensure-cases (sequence-number origin expected)
`((0 nil nil)
(0
,(make-id "D8FBFEF4-4EB0-4C89-9716-C425DED3C527")
,(make-id "84F43861-433F-5253-AFBB-A613A5E04D71"))
(378
,(make-id "BF948D47-618F-4B04-AAC5-0AB5A1A79267")
,(make-id "BD27BE7D-87DE-5336-BECA-44FC60DE46A0")))
(let ((event (apply #'make-instance 'event
:sequence-number sequence-number
:scope (make-scope "/")
(when origin
(list :origin origin)))))
(if expected
(ensure-same (event-id event) expected
:test #'uuid:uuid=)
(ensure-null (event-id event))))))
(addtest (event-root
:documentation
"Test comparing events for equality using `event='.")
comparison
(ensure-cases (scope1 data1 origin1?
scope2 data2 origin2?
=1? =2? =3? =4? =5?)
'(("/" "bar" nil "/" "bar" nil t nil t nil t)
("/" "bar" t "/" "bar" nil t nil nil nil t)
("/" "bar" t "/" "bar" t t nil t nil t)
("/foo" "bar" nil "/" "bar" nil nil nil nil nil nil)
("/" "baz" nil "/" "bar" nil nil nil nil nil nil))
(let* ((origin (uuid:make-v1-uuid))
(left (make-event scope1 data1))
(right (progn
(sleep .000001) ;; force different create times
(make-event scope2 data2)) ))
(setf (event-sequence-number left) 0)
(when origin1?
(setf (event-origin left) origin))
(setf (event-sequence-number right) 1)
(when origin2?
(setf (event-origin right) origin))
(iter (for (sequence-numbers? origins? timestamps? causes? expected)
in `((nil nil nil nil ,=1?)
(t nil nil nil ,=2?)
(nil t nil nil ,=3?)
(nil nil t nil ,=4?)
(nil nil nil t ,=5?)))
(ensure-same
(event= left right
:compare-sequence-numbers? sequence-numbers?
:compare-origins? origins?
:compare-timestamps timestamps?
:compare-causes? causes?
:data-test #'equal)
expected
:report "~@<When compared ~:[without~;with~] sequence ~
numbers, ~:[without~;with~] origins, ~
~:[without~;with~] timestamps and ~
~:[without~;with~] causes, events ~A and ~A were ~
~:[not ~;~]equal, but expected ~:[not ~;~]to ~
be.~@:>"
:arguments (sequence-numbers? origins? timestamps? causes?
left right (not expected) expected))))))
(addtest (event-root
:documentation
"Test `print-object' method on `event' class.")
print
(ensure-cases (args expected)
`((("/foo/bar" "baz")
"/foo/bar/ \"baz\" (3)")
(("/foo/bar" ,(make-string 1000 :initial-element #\a))
"/foo/bar/ \"aaaaaaaaaa...\" (1000)")
(("/foo/bar" "with
newline")
"/foo/bar/ \"with.newli...\" (12)")
(("/" ,(make-scope "/foo/bar/"))
"/ /foo/bar/"))
(let+ ((event (apply #'make-event args))
(string (let ((*print-length* 10))
(princ-to-string event)))
((&flet search/flipped (string expected)
(search expected string))))
(ensure-same string expected :test #'search/flipped))))
| 7,408 | Common Lisp | .lisp | 163 | 32.791411 | 84 | 0.494184 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 954a667a0e62b2118640e45461131fc88720316873e7726093d6a5b50d036592 | 25,161 | [
-1
] |
25,162 | protocol.lisp | open-rsx_rsb-cl/test/protocol.lisp | ;;;; protocol.lisp --- Unit tests for the protocol of the rsb system.
;;;;
;;;; Copyright (C) 2014-2019 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.test)
;;; Tests for the `make-participant' generic function
(deftestsuite make-participant-root (root)
()
(:documentation
"Unit tests for the `participant-hook' generic function."))
(defclass nested-mock-participant.inner (participant) ())
(rsb::register-participant-class 'nested-mock-participant.inner)
(defmethod initialize-instance :after ((instance nested-mock-participant.inner)
&key
scope
signal-participant-creation-error?
&allow-other-keys)
(if signal-participant-creation-error?
(error 'participant-creation-error
:kind :nested-mock-participant.inner
:scope scope
:transports '())
(error "intentional error")))
(defclass nested-mock-participant.outer (participant) ())
(rsb::register-participant-class 'nested-mock-participant.outer)
(defmethod initialize-instance :after ((instance nested-mock-participant.outer)
&key
signal-participant-creation-error?
&allow-other-keys)
(make-participant :nested-mock-participant.inner "/"
:signal-participant-creation-error?
signal-participant-creation-error?))
(defun caused-by-intentional-error? (condition)
(flet ((check-one (condition kind)
(and (typep condition 'participant-creation-error)
(eq (participant-creation-error-kind condition) kind))))
(and (check-one condition :nested-mock-participant.outer)
(check-one (cause condition) :nested-mock-participant.inner)
(typep (cause (cause condition)) 'simple-error)
(string= (princ-to-string (cause (cause condition)))
"intentional error"))))
(deftype caused-by-intentional-error ()
'(satisfies caused-by-intentional-error?))
(defun caused-by-same? (condition)
(flet ((check-one (condition kind)
(and (typep condition 'participant-creation-error)
(eq (participant-creation-error-kind condition) kind))))
(and (check-one condition :nested-mock-participant.outer)
(check-one (cause condition) :nested-mock-participant.inner)
(null (cause (cause condition))))))
(deftype caused-by-same ()
'(satisfies caused-by-same?))
(addtest (make-participant-root
:documentation
"Test chaining of `participant-creation-error' conditions in
case of recursive `make-participant' calls.")
error-from-nested-call
(let+ (((&flet do-it (scope &rest initargs)
(apply #'make-participant :nested-mock-participant.outer scope
initargs)))
((&flet test-case (expected &rest args)
(ecase expected
(caused-by-intentional-error
(ensure-condition 'caused-by-intentional-error
(apply #'do-it args)))
(caused-by-same
(ensure-condition 'caused-by-same
(apply #'do-it args)))))))
(test-case 'caused-by-intentional-error "/")
(test-case 'caused-by-intentional-error (puri:uri "/"))
(test-case 'caused-by-intentional-error (make-scope "/"))
(test-case 'caused-by-same "/"
:signal-participant-creation-error? t)
(test-case 'caused-by-same (puri:uri "/")
:signal-participant-creation-error? t)
(test-case 'caused-by-same (make-scope "/")
:signal-participant-creation-error? t)))
;;; Hook tests
(deftestsuite hooks-root (root)
()
(:documentation
"Unit tests for `*make-participant-hook*' and
`*participant-state-change-hook*'."))
(defun call-with-hook-call-tracking (hook thunk
&key
handler)
(let ((hook-calls '()))
(hooks:with-handlers
((hook (lambda (&rest args)
(appendf hook-calls (list args))
(if handler
(apply handler args)
(values))
(first args))))
(funcall thunk))
hook-calls))
(defmacro with-hook-call-tracking ((hook &optional calls-place) &body body)
(let+ (((&flet make-call ()
`(call-with-hook-call-tracking ',hook (lambda () ,@body)))))
(if calls-place
`(setf ,calls-place ,(make-call))
(make-call))))
(addtest (hooks-root
:documentation
"Smoke test for `*make-participant-hook*'.")
make-participant-hook/smoke
(ensure-cases ((kind scope &rest args) &rest expected)
`(((:reader "inprocess:/rsbtest/make-participant-hook/smoke")
(:converters :transports :introspection?)
(:introspection? :parent :handlers :error-policy
:transports :converters :transform))
((:reader "inprocess:/rsbtest/make-participant-hook/smoke"
:parent ,*simple-parent*)
(:converters :transports :introspection? :parent)
(:introspection? :parent :handlers :error-policy
:transports :converters :transform))
;; Hook calls caused by introspection stuff interfere too
;; much.
;; ((:reader "inprocess:/rsbtest/make-participant-hook/smoke"
;; :introspection? t)
;; (:converters :transports :introspection?)
;; (:introspection? :parent :handlers :error-policy
;; :transports :converters :transform))
((:reader "inprocess:/rsbtest/make-participant-hook/smoke"
:transform nil)
(:converters :transports :introspection? :transform)
(:introspection? :parent :handlers :error-policy
:transports :converters :transform))
((:listener "inprocess:/rsbtest/make-participant-hook/smoke")
(:converters :transports :introspection?))
((:listener "inprocess:/rsbtest/make-participant-hook/smoke"
:parent ,*simple-parent*)
(:converters :transports :introspection? :parent))
((:listener "inprocess:/rsbtest/make-participant-hook/smoke"
:introspection? t)
(:converters :transports :introspection?))
((:listener "inprocess:/rsbtest/make-participant-hook/smoke"
:transform nil)
(:converters :transports :introspection? :transform))
((:informer "inprocess:/rsbtest/make-participant-hook/smoke"
:type t)
(:converters :transports :type :introspection?))
((:informer "inprocess:/rsbtest/make-participant-hook/smoke"
:type t :parent ,*simple-parent*)
(:converters :transports :type :introspection? :parent))
((:informer "inprocess:/rsbtest/make-participant-hook/smoke"
:type t :introspection? t)
(:converters :transports :type :introspection?))
((:informer "inprocess:/rsbtest/make-participant-hook/smoke"
:type t :transform nil)
(:converters :transports :type :introspection? :transform))
((:local-server "inprocess:/rsbtest/make-participant-hook/smoke")
(:converters :transports :introspection?))
((:local-server "inprocess:/rsbtest/make-participant-hook/smoke"
:parent ,*simple-parent*)
(:converters :transports :introspection? :parent))
((:local-server "inprocess:/rsbtest/make-participant-hook/smoke"
:introspection? t)
(:converters :transports :introspection?))
((:local-server "inprocess:/rsbtest/make-participant-hook/smoke"
:transform nil)
(:converters :transports :introspection? :transform))
((:remote-server "inprocess:/rsbtest/make-participant-hook/smoke")
(:converters :transports :introspection?))
((:remote-server "inprocess:/rsbtest/make-participant-hook/smoke"
:parent ,*simple-parent*)
(:converters :transports :introspection? :parent))
((:remote-server "inprocess:/rsbtest/make-participant-hook/smoke"
:introspection? t)
(:converters :transports :introspection?))
((:remote-server "inprocess:/rsbtest/make-participant-hook/smoke"
:transform nil)
(:converters :transports :introspection? :transform)))
(let ((participant)
(child))
(ensure-same
(with-hook-call-tracking (*make-participant-hook*)
(with-active-participant (participant1 (apply #'make-participant
kind scope args))
(setf participant participant1)
(when (typep participant1 'rsb.patterns.reader:reader)
(setf child (rsb.patterns:participant-child
participant1 nil :listener)))))
(append (when child
(list (list child (second expected))))
(list (list participant (first expected))))
:test (lambda (calls expected)
(every
(lambda+ ((call-participant call-initargs)
(expected-participant expected-initargs))
(ensure-same call-participant expected-participant)
(ensure-same
(iter (for (key _) :on call-initargs :by #'cddr) (collect key))
expected-initargs
:test #'set-equal))
calls expected))))))
(define-condition buggy-handler-error (error) ())
(defun participant-creation-error-caused-by-buggy-handler-error? (thing)
(and (typep thing 'participant-creation-error)
(typep (cause thing) 'buggy-handler-error)))
(deftype participant-creation-error-caused-by-buggy-handler-error ()
'(satisfies participant-creation-error-caused-by-buggy-handler-error?))
(addtest (hooks-root
:documentation
"Test signaled error in case of a buggy handler in
`*make-participant-hook*'.")
make-participant-hook/buggy-handler
(let+ ((scope "/rsbtest/make-participant-hook/buggy-handler")
(uri (concatenate 'string "inprocess:" scope))
((&flet do-it (&optional thunk)
(hooks:with-handlers (('*make-participant-hook*
(lambda (&rest args)
(declare (ignore args))
(error 'buggy-handler-error))))
(with-participant (participant :listener uri)
(when thunk (funcall thunk participant)))))))
;; Without invoking restarts, the condition should be wrapped in a
;; `participant-creation-error'.
(ensure-condition
'participant-creation-error-caused-by-buggy-handler-error
(do-it))
;; Skip the buggy handler by using the `continue' restart. Make
;; sure we get the requested participant instance in this case.
(handler-bind ((error #'continue))
(do-it (rcurry #'check-participant :listener scope)))))
(addtest (hooks-root
:documentation
"Smoke test for `*participant-state-change-hook*'")
participant-state-change-hook/smoke
(ensure-cases (kind scope &rest args)
'((:reader "inprocess:/rsbtest/participant-state-change-hook/smoke")
(:listener "inprocess:/rsbtest/participant-state-change-hook/smoke")
(:informer "inprocess:/rsbtest/participant-state-change-hook/smoke"
:type t)
(:local-server "inprocess:/rsbtest/participant-state-change-hook/smoke")
(:remote-server "inprocess:/rsbtest/participant-state-change-hook/smoke"))
(let ((participant)
(child))
(ensure-same
(with-hook-call-tracking (*participant-state-change-hook*)
(with-active-participant
(participant1 (apply #'make-participant kind scope args))
(setf participant participant1)
(when (typep participant1 'rsb.patterns.reader:reader)
(setf child (rsb.patterns:participant-child
participant1 nil :listener)))))
(append (when child
(list (list child :detached)))
(list (list participant :detached)))
:test #'equal))))
| 12,715 | Common Lisp | .lisp | 251 | 38.87251 | 82 | 0.598616 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 3452da86eb9eb400ed7eb9552f3b0115c0106ec6d97de3b1bec6b9db3a78fb5b | 25,162 | [
-1
] |
25,163 | builder.lisp | open-rsx_rsb-cl/test/builder.lisp | ;;;; builder.lisp --- Unit tests for builder support.
;;;;
;;;; Copyright (C) 2015, 2016 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:defpackage #:rsb.builder.test
(:use
#:cl
#:alexandria
#:let-plus
#:lift
#:rsb
#:rsb.builder)
(:local-nicknames
(#:bp #:architecture.builder-protocol))
(:import-from #:architecture.builder-protocol.test
#:record-un-build-calls/peeking)
(:export
#:rsb-builder-root)
(:documentation
"This package contains test for the builder module."))
(cl:in-package #:rsb.builder.test)
(deftestsuite rsb-builder-root (root)
()
(:documentation
"Unit tests for builder support."))
(defun check-un-build-calls (builder atom-type cases &key peek-function)
(mapc (lambda+ ((object expected-calls))
(let+ (((&values &ign calls)
(record-un-build-calls/peeking
#'bp:walk-nodes builder atom-type object
:peek-function peek-function)))
(ensure-same calls expected-calls :test #'equal)))
cases))
(addtest (rsb-builder-root
:documentation
"Smoke test for \"unbuilding\" `scope' instances.")
scope/smoke
(check-un-build-calls
t 'string
`(,(let ((scope (make-scope "/")))
`(,scope ((:peek nil () ,scope)
(:visit nil () ,scope rsb:scope ((:component . *)) ()))))
,(let ((scope (make-scope "/foo/bar")))
`(,scope ((:peek nil () ,scope)
(:visit nil () ,scope rsb:scope ((:component . *)) ())
(:peek :component () "foo")
(:peek :component () "bar")))))))
(addtest (rsb-builder-root
:documentation
"Smoke test for the \"unbuilding\" `event' instances.")
event/smoke
(check-un-build-calls
t '(or number string
uuid:uuid local-time:timestamp
puri:uri scope)
`(;; Almost maximal event.
,(let* ((scope (make-scope "/foo"))
(create (local-time:now))
(event (make-event scope "baz"
:method :|request|
:timestamps (list :create create)
:create-timestamp? nil
:foo "bar")))
`(,event ((:peek nil () ,event)
(:visit nil () ,event rsb:event
((:meta-data . (:map . :key))
(:timestamp . (:map . :key))
(:cause . *)
(:data . 1))
(:scope ,scope :method :|request|))
(:peek :meta-data (:key :foo) "bar")
(:peek :timestamp (:key :create) ,create)
(:peek :data () "baz"))))
;; Minimal event, in particular without method.
,(let* ((scope (make-scope "/foo"))
(event (make-event scope "baz" :create-timestamp? nil)))
`(,event ((:peek nil () ,event)
(:visit nil () ,event rsb:event
((:meta-data . (:map . :key))
(:timestamp . (:map . :key))
(:cause . *)
(:data . 1))
(:scope ,scope))
(:peek :data () "baz")))))))
(defclass mock-payload ()
((slot :initarg :slot
:type vector
:initform #(1 2))))
(addtest (rsb-builder-root
:documentation
"Smoke test for \"unbuilding\" `event' instances, switching
to universal builder for the data relation.")
event/universal-builder-for-event-data
(check-un-build-calls
t '(or number string
uuid:uuid local-time:timestamp
puri:uri scope)
`(,(let* ((scope (make-scope "/foo"))
(data (make-instance 'mock-payload))
(create (local-time:now))
(event (make-event scope data
:method :|request|
:timestamps (list :create create)
:create-timestamp? nil
:foo "bar")))
`(,event ((:peek nil () ,event)
(:visit nil () ,event rsb:event
((:meta-data . (:map . :key))
(:timestamp . (:map . :key))
(:cause . *)
(:data . 1))
(:scope ,scope :method :|request|))
(:peek :meta-data (:key :foo) "bar")
(:peek :timestamp (:key :create) ,create)
(:peek :data () ,data)
(:visit :data () ,data mock-payload
((:slot . *))
())
(:peek :slot () 1)
(:peek :slot () 2)))))
:peek-function (universal-builder-for-event-data)))
| 5,237 | Common Lisp | .lisp | 122 | 29.754098 | 82 | 0.445447 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 09a1ad8f28497ab07193fd2ef19f4784d1eb71658a645da3228c3c3eea021c05 | 25,163 | [
-1
] |
25,164 | configuration.lisp | open-rsx_rsb-cl/test/configuration.lisp | ;;;; configuration.lisp --- Unit tests for configuration functions.
;;;;
;;;; Copyright (C) 2014, 2015 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.test)
(deftestsuite configuration-root (root)
()
(:documentation
"Unit tests for configuration functions."))
(addtest (configuration-root
:documentation
"Smoke test for the `transport-options'.")
transport-options/smoke
(ensure-cases (options expected)
'(;; Empty and not transport-related.
(() ())
((((:foo) . 1)) ())
((((:foo :bar) . 1)) ())
;; Basic Transport options.
((((:transport :foo :bar) . 1)) ((:foo . (:bar 1))))
((((:transport :foo :bar) . 1)
((:transport :foo :fez) . 2)) ((:foo . (:bar 1 :fez 2))))
((((:transport :foo :bar) . 1)
((:transport :fez :whoop) . 2)) ((:foo . (:bar 1))
(:fez . (:whoop 2))))
;; Converter options.
((((:transport :foo :converters :lisp :foo) . "bar")) ((:foo . ())))
;; Unrelated converter options.
((((:transport :foo :converters :cpp :foo) . "bar")) ((:foo . ()))))
(ensure-same (rsb::transport-options options) expected :test #'equal)))
(addtest (configuration-root
:documentation
"Smoke test for the (internal) `effective-transport-options'
function.")
effective-transport-options/smoke
(ensure-cases (options expected)
'(;; Nothing.
(() ())
;; Some transport.
(((:socket :enabled nil)) ())
(((:socket :enabled nil :port 1)) ())
(((:socket :enabled t)) ((:socket)))
(((:socket :enabled t :port 1)) ((:socket :port 1)))
;; Only defaults.
(((t :enabled nil)) ())
(((t :enabled nil :port 1)) ())
(((t :enabled t)) ())
(((t :enabled t :port 1)) ())
;; Transport and defaults without inheritance.
(((:socket) (t :enabled t)) ())
(((:socket :port 1) (t :enabled t)) ())
(((:socket) (t :enabled nil)) ())
(((:socket :port 1) (t :enabled nil)) ())
(((:socket :enabled nil) (t :enabled t)) ())
(((:socket :enabled nil :port 1) (t :enabled t)) ())
(((:socket :enabled t) (t :enabled t)) ((:socket)))
(((:socket :enabled t :port 1) (t :enabled t)) ((:socket :port 1)))
(((:socket :enabled nil) (t :enabled nil)) ())
(((:socket :enabled nil :port 1) (t :enabled nil)) ())
(((:socket :enabled t) (t :enabled nil)) ((:socket)))
(((:socket :enabled t :port 1) (t :enabled nil)) ((:socket :port 1)))
;; Transport and defaults with inheritance.
(((:socket &inherit) (t :enabled t)) ())
(((:socket :port 1 &inherit) (t :enabled t)) ())
(((:socket &inherit) (t :enabled nil)) ())
(((:socket :port 1 &inherit) (t :enabled nil)) ())
(((:socket :enabled nil &inherit) (t :enabled t)) ())
(((:socket :enabled nil :port 1 &inherit) (t :enabled t)) ())
(((:socket :enabled t &inherit) (t :enabled t)) ((:socket)))
(((:socket :enabled t :port 1 &inherit) (t :enabled t)) ((:socket :port 1)))
(((:socket :enabled nil &inherit) (t :enabled nil)) ())
(((:socket :enabled nil :port 1 &inherit) (t :enabled nil)) ())
(((:socket :enabled t &inherit) (t :enabled nil)) ((:socket)))
(((:socket :enabled t :port 1 &inherit) (t :enabled nil)) ((:socket :port 1))))
(let ((original (copy-tree options))
(result (rsb::effective-transport-options options)))
(ensure-same result expected :test #'equal)
(ensure-same options original :test #'equal))))
(addtest (configuration-root
:documentation
"Smoke test for the (internal) `merge-transport-options'
function.")
merge-transport-options/smoke
(ensure-cases (left right expected)
'(;; Nothing
(()
()
())
;; Transport without defaults.
(((:socket :port 1))
()
((:socket :port 1)))
;; Defaults without transport.
(()
((:socket :port 1))
((:socket :port 1)))
;; Transport and defaults.
(((:socket :port 1))
((:socket :host "foo"))
((:socket :port 1)))
;; Transport with inheritance but no defaults.
(((:socket :port 1 &inherit) (t :host "foo"))
()
((:socket :port 1 :host "foo") (t :host "foo")))
;; Transport with inheritance and defaults.
(((:socket :port 1 &inherit))
((:socket :host "foo"))
((:socket :port 1 :host "foo"))))
(let ((original-left (copy-tree left))
(original-right (copy-tree right))
(result (rsb::merge-transport-options left right)))
(ensure-same result expected :test #'equal)
(ensure-same left original-left :test #'equal)
(ensure-same right original-right :test #'equal))))
| 5,820 | Common Lisp | .lisp | 115 | 42.756522 | 89 | 0.458121 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 7cb8c0cfcb7e00a42304f178f4f9bb847a627a63c2dfc8c163e14ae5ade5f172 | 25,164 | [
-1
] |
25,165 | participant.lisp | open-rsx_rsb-cl/test/participant.lisp | ;;;; participant.lisp --- Unit tests for the participant class.
;;;;
;;;; Copyright (C) 2011-2017 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.test)
(deftestsuite participant-root (root)
()
(:documentation
"Test suite for the `participant' class."))
(addtest (participant-root
:documentation
"Test method on `participant-converter' for the
`participant' class.")
participant-converter
(ensure-cases (converters query error? expected)
'((() number nil ())
(() number t :error)
(((number . :a) (integer . :b)) number nil (:a))
(((number . :a) (integer . :b)) integer nil (:a :b))
(((number . :a) (integer . :b)) string nil ())
(((number . :a) (integer . :b)) string t :error))
(let ((participant (make-instance 'participant
:scope "/"
:converters converters)))
(if (eq expected :error)
(ensure-condition 'error
(participant-converter participant query
:error? error?))
(let ((result (participant-converter participant query
:error? error?)))
(ensure-same result expected
:test #'set-equal))))))
(addtest (participant-root
:documentation
"Ensure that the specified error policy is in effect when
connector-related errors become possible.")
error-policy-race
;; The following code was previously racy and would sometimes signal
;; an error because the error signaling event handler in HANDLERS
;; would be executed before the `continue' error policy was
;; installed in the listener.
(with-participant (informer :informer "inprocess:")
(let ((send (lambda () (send informer "")))
(handlers (list (lambda (event)
(declare (ignore event))
(error "~@<intentional error~@:>")))))
(iter (repeat 1000)
(iter (repeat 3) (bt:make-thread send))
(with-participant
(listener :listener "inprocess:"
:error-policy #'continue
:handlers handlers)
(declare (ignore listener)))))))
(defclass mock-cleanup-participant (participant)
((cleanup :initarg :cleanup
:reader cleanup)))
(defmethod shared-initialize :after ((instance mock-cleanup-participant)
(slot-names t)
&key)
(error "something went wrong"))
(defmethod detach ((participant mock-cleanup-participant))
(funcall (cleanup participant))
(error "another thing went wrong"))
(addtest (participant-root
:documentation
"Ensure that `detach' is called when an error is signaled
during initialization.")
failed-construction-cleanup
;; Make that the cleanup code in the `detach' method is executed.
(let+ ((cleanup? nil)
((&flet cleanup () (setf cleanup? t))))
(ensure-condition 'error
(make-instance 'mock-cleanup-participant
:scope "/participantroot/failedconstructioncleanup"
:cleanup #'cleanup))
(ensure cleanup?)))
| 3,453 | Common Lisp | .lisp | 77 | 33.974026 | 74 | 0.565398 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | e12003beb9894ded19d08de2891e7fe9bda3cb6fb7648565b21c6f8cdeceb5bb | 25,165 | [
-1
] |
25,166 | examples.lisp | open-rsx_rsb-cl/test/examples.lisp | ;;;; examples.lisp --- Tests of example programs.
;;;;
;;;; Copyright (C) 2014, 2016 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.test)
(define-constant +terminate-marker+
"Loading this file does not terminate"
:test #'string=)
(defun test-example (file &key (trace-stream *trace-output*))
(format trace-stream "/// Begin example ~24,0T~S~%" file)
(unwind-protect
(let+ ((does-not-terminate?
(search +terminate-marker+
(read-file-into-string file)))
(stream (make-string-output-stream))
((&values output-file warnings? failure?)
(let ((*standard-output* stream)
(*error-output* stream))
(handler-bind ((warning #'muffle-warning))
(format trace-stream "/// Compiling example ~24,0T~S~%" file)
(with-standard-io-syntax
(let ((*print-readably* nil)) ; SBCL workaround
(with-compilation-unit (:override t)
(compile-file file))))))))
(cond
((or warnings? failure?)
(error "~@<Failed to compile example file ~S~@:_~@:_~
~2@T~<~@;~A~:>~:>"
file (list (get-output-stream-string stream))))
(does-not-terminate?
(format trace-stream "/// Not loading example ~24,0T~S~%~
/// ~24,0TThe file is marked to not ~
terminate when loaded~%"
file))
(t
(handler-case
(progn
(format trace-stream "/// Loading example ~24,0T~S~2%~2@T" file)
(pprint-logical-block (trace-stream (list) :per-line-prefix "> ")
(let ((*package* (find-package '#:cl-user))
(*standard-output* trace-stream))
(load output-file))))
(error (condition)
(error "~@<Failed to load example file ~S~@:_~@:_~
~2@T~<| ~@;~A~:>~
~:>"
file (list condition))))
(format trace-stream "~2%"))))
(format trace-stream "~&/// End example ~24,0T~S~2%" file)))
(defun example-files ()
(directory (merge-pathnames "**/*.lisp"
(asdf:system-relative-pathname
:rsb "examples/"))))
(deftestsuite examples-root (root)
()
(:timeout 60)
(:documentation
"Test suite for compiling and loading example files in the examples
directory."))
(addtest (examples-root
:documentation
"Test compiling and loading example files in the examples
directory.")
compile-and-load
(ensure-cases (file)
(example-files)
(test-example file)))
| 2,929 | Common Lisp | .lisp | 68 | 30.088235 | 83 | 0.507363 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 5adf43ad64903c09f9319f4ab298fe8cc8961428507a4075b4f875201cccae35 | 25,166 | [
-1
] |
25,167 | listener.lisp | open-rsx_rsb-cl/test/listener.lisp | ;;;; listener.lisp --- Unit tests for listener.
;;;;
;;;; Copyright (C) 2011-2016 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.test)
(deftestsuite listener-root (root
participant-suite)
()
(:function
(send-some (informer)
(iter (repeat 100)
(send informer "foo")
(send informer "bar"))))
(:documentation
"Unit tests for the `listener' class."))
(define-basic-participant-test-cases listener
'("/rsbtest/listener/construction"
()
"/rsbtest/listener/construction")
'("/rsbtest/listener/construction"
(:transports ((:inprocess &inherit)))
"/rsbtest/listener/construction")
'("/rsbtest/listener/construction"
(:transports ((t &inherit) (:inprocess &inherit)))
"/rsbtest/listener/construction")
'("/rsbtest/listener/construction"
(:converters ((t . :foo)))
"/rsbtest/listener/construction")
`("/rsbtest/listener/construction"
(:transform ,#'1+)
"/rsbtest/listener/construction")
`("/rsbtest/listener/construction"
(:parent ,*simple-parent*)
"/rsbtest/listener/construction")
'("/rsbtest/listener/construction"
(:introspection? nil)
"/rsbtest/listener/construction")
'("/rsbtest/listener/construction"
(:introspection? t)
"/rsbtest/listener/construction")
'("inprocess:/rsbtest/listener/construction"
()
"/rsbtest/listener/construction")
`("inprocess:/rsbtest/listener/construction"
(:error-policy ,#'continue)
"/rsbtest/listener/construction")
`("/rsbtest/listener/construction?foo=bar"
()
"/rsbtest/listener/construction")
;; Handlers
`("/rsbtest/listener/construction"
(:handlers (list (lambda (event) (declare (ignore event)))))
"/rsbtest/listener/construction")
;; Filters
`("/rsbtest/listener/construction"
(:filters (list (lambda (event) (declare (ignore event)))))
"/rsbtest/listener/construction")
;; No transports => error
'("/rsbtest/listener/construction"
(:transports ((t :enabled nil)))
error))
(addtest (listener-root
:documentation
"Test adding and removing handlers to/from a `listener'
instance.")
handlers
(with-participant (listener :listener "/foo")
;; Initially, there should not be any handlers.
(ensure-null (rsb.ep:handlers listener))
;; Test adding and removing a handler.
(let ((handler (lambda (event) (declare (ignore event)))))
(push handler (rsb.ep:handlers listener))
(ensure-same (rsb.ep:handlers listener) (list handler)
:test #'equal)
(removef (rsb.ep:handlers listener) handler)
(ensure-null (rsb.ep:handlers listener)))))
(addtest (listener-root
:documentation
"Test receiving data sent by an informer.")
receive
(with-participant (informer :informer "/rsbtest/listener/receive")
(with-participant (listener :listener "/rsbtest/listener/receive")
;; Test receive
(send-some informer)
;; Test receive with filters
(push (filter :origin :origin (uuid:make-v1-uuid))
(receiver-filters listener))
(send-some informer)
;; Test receive with handlers
(push (lambda (event) (declare (ignore event)))
(rsb.ep:handlers listener))
(send-some informer))))
(define-error-hook-test-case (listener)
;; Force an error during dispatch by injecting a signaling
;; pseudo-filter.
(push (lambda (event)
(let ((error (make-condition 'simple-error
:format-control "I hate ~A"
:format-arguments (list event))))
(push error expected-errors)
(error error)))
(receiver-filters listener))
;; Try to send and receive an event to trigger the error.
(send informer "foo"))
| 3,885 | Common Lisp | .lisp | 105 | 30.733333 | 72 | 0.654768 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 50acc7606f48d6ce48ba680631fba6361d3f3ab733b340f1ab4d759436215ad2 | 25,167 | [
-1
] |
25,168 | macros.lisp | open-rsx_rsb-cl/test/macros.lisp | ;;;; macros.lisp --- Unit tests for macros.
;;;;
;;;; Copyright (C) 2011-2017 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.test)
(deftestsuite macros-root (root
participant-suite)
()
(:documentation
"Unit tests for macros provided by the rsb system."))
(addtest (macros-root
:documentation
"Test creating an anonymous participant using the
`with-participant' macro.")
with-participant/anonymous
(with-participant (nil :listener "/rsbtest/macros-root/with-participant/anonymous")))
;;; Test `with-participant' macro with `listener' and test
;;; `listener'-related macros
(addtest (macros-root
:documentation
"Smoke test for the `with-participant' macro with
a :listener participant.")
with-participant/listener/smoke
(with-participant (listener :listener "/rsbtest/macros-root/with-participant/listener/smoke")
(ensure (typep listener 'listener))
(check-participant listener :listener "/rsbtest/macros-root/with-participant/listener/smoke")))
(addtest (macros-root
:documentation
"Test handling of error-policy keyword parameter in
`with-participant' macro with a :listener participant.")
with-participant/listener/error-policy
(let ((calls '())
(received '()))
(macrolet
((test-case (&optional policy)
`(with-participant (listener :listener "/rsbtest/macros-root/with-listener/error-policy"
:transform #'mock-transform/error
,@(when policy `(:error-policy ,policy)))
(with-handler listener ((event) (push event received))
(with-participant (informer :informer "/rsbtest/macros-root/with-listener/error-policy")
(send informer 1))))))
;; Without an error policy, the transform error should just be
;; signaled.
(ensure-condition rsb.transform:transform-error
(test-case))
;; With `continue' error policy, receiving and dispatching of
;; the event should proceed without the failing transformation.
(let ((result (test-case (lambda (condition)
(push condition calls)
(continue condition)))))
(ensure (typep result 'event))
(ensure-same (length calls) 1)
(ensure (typep (first calls) 'rsb.transform:transform-error))
(ensure-same (length received) 1)))))
(addtest (macros-root
:documentation
"Smoke test for the `with-handler' macro.")
with-handler/smoke
(let ((received '()))
(with-participant (listener :listener "/rsbtest/macros-root/with-handler/smoke")
(with-handler listener ((event) (push event received))
(ensure (typep listener 'listener))
(check-participant listener :listener "/rsbtest/macros-root/with-handler/smoke")
(with-participant (informer :informer "/rsbtest/macros-root/with-handler/smoke")
(send informer 1))))
(ensure-same (length received) 1)))
;;; Reader-related macros
(addtest (macros-root
:documentation
"Smoke test for the `with-participant' macro with a :reader
participant.")
with-participant/reader/smoke
(with-participant (reader :reader "/rsbtest/macros-root/with-participant/reader/smoke")
(ensure (typep reader 'reader))
(check-participant reader :reader "/rsbtest/macros-root/with-participant/reader/smoke")))
(addtest (macros-root
:documentation
"Test handling of error-policy keyword parameter in
`with-participant' macro with a :reader participant.")
with-participant/reader/error-policy
(let ((calls '()))
(macrolet
((test-case (&optional policy)
`(with-participant (reader :reader "/rsbtest/macros-root/with-participant/reader/error-policy"
:transform #'mock-transform/error
,@(when policy `(:error-policy ,policy)))
(with-participant (informer :informer "/rsbtest/macros-root/with-participant/reader/error-policy")
(send informer 1))
(receive reader))))
;; Without an error policy, the transform error should just be
;; signaled.
(ensure-condition rsb.transform:transform-error
(test-case))
;; With `continue' error policy, sending the event should proceed
;; without the failing transformation.
(let ((result (test-case (lambda (condition)
(push condition calls)
(continue condition)))))
(ensure (typep result 'event))
(ensure-same (length calls) 1)
(ensure (typep (first calls) 'rsb.transform:transform-error))))))
;;; Informer-related macros
(addtest (macros-root
:documentation
"Smoke test for the `with-participant' macro with
a :informer participant.")
with-participant/informer/smoke
(with-participant (informer :informer "/rsbtest/macros-root/with-participant/informer/smoke")
(ensure (typep informer 'informer))
(check-participant informer :informer "/rsbtest/macros-root/with-participant/informer/smoke")))
(addtest (macros-root
:documentation
"Test handling of error-policy keyword parameter in
`with-participant' macro with a :informer participant.")
with-participant/informer/error-policy
(let ((calls '()))
(macrolet
((test-case (&optional policy)
`(with-participant (informer :informer "/rsbtest/macros-root/with-informer/error-policy"
:transform #'mock-transform/error
,@(when policy `(:error-policy ,policy)))
(send informer 1))))
;; Without an error policy, the transform error should just be
;; signaled.
(ensure-condition rsb.transform:transform-error
(test-case))
;; With `continue' error policy, sending the event should proceed
;; without the failing transformation.
(let ((result (test-case (lambda (condition)
(push condition calls)
(continue condition)))))
(ensure (typep result 'event))
(ensure-same (length calls) 1)
(ensure (typep (first calls) 'rsb.transform:transform-error))))))
| 6,540 | Common Lisp | .lisp | 135 | 38.325926 | 112 | 0.632957 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 1ae73e4619f9104c422a1f9a159963b5b3bca10c231bf4cc4235c5d7d3dab92c | 25,168 | [
-1
] |
25,169 | mixins.lisp | open-rsx_rsb-cl/test/mixins.lisp | ;;;; mixins.lisp --- Unit tests for mixins classes.
;;;;
;;;; Copyright (C) 2013, 2014 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.test)
(deftestsuite uuid-mixin-root (root)
()
(:documentation
"Test suite for the `uuid-mixin' class."))
(addtest (uuid-mixin-root
:documentation
"Test constructing `uuid-mixin' instances for different
values of `*id-random-state*'.")
random-state
;; Binding `*id-random-state*' to identical values has to result in
;; `uuid-mixin' instances with identical ids.
(let+ ((state (make-random-state))
((&values a b)
(values
(let ((*id-random-state* (make-random-state state)))
(make-instance 'uuid-mixin))
(let ((*id-random-state* (make-random-state state)))
(make-instance 'uuid-mixin)))))
(ensure-same (slot-value a 'rsb::id) (slot-value b 'rsb::id)
:test #'uuid:uuid=))
;; Using the current value of `*id-random-state*' multiple times has
;; to result in different ids.
(ensure-different
(slot-value (make-instance 'uuid-mixin) 'rsb::id)
(slot-value (make-instance 'uuid-mixin) 'rsb::id)
:test #'uuid:uuid=))
| 1,239 | Common Lisp | .lisp | 32 | 33.25 | 70 | 0.638103 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 435b12d44cc8ffcced389219f91958491a5e3a63d6850cc9a515b5080fb4d117 | 25,169 | [
-1
] |
25,170 | uris.lisp | open-rsx_rsb-cl/test/uris.lisp | ;;;; uris.lisp --- Unit tests for URI-related functions.
;;;;
;;;; Copyright (C) 2011, 2012, 2013, 2014 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.test)
(deftestsuite uris-root (root)
()
(:documentation
"Unit tests for URI-related functions."))
(addtest (uris-root
:documentation
"Smoke test for the `uri-options' function.")
uri-options-smoke
(ensure-cases (uri-string expected)
'(;; Some illegal cases.
("?scheme=foo" error)
("?host=foo" error)
("?port=4444" error)
;; These are allowed.
("" ())
("spread:" ())
("?" ())
("?foo=bar" (:foo "bar"))
("?bar=baz;whoop=nooble" (:bar "baz" :whoop "nooble"))
("?first=yes&=yes" (:first "yes" :amp "yes")))
(let+ (((&flet do-it ()
(let ((uri (puri:parse-uri uri-string)))
(values (uri-options uri) uri)))))
(case expected
(error
(ensure-condition 'error (do-it)))
(t
(let+ (((&values options uri) (do-it)))
(ensure-same options expected
:test #'equal
:report "~@<Extracted options from URI ~S are ~
~S, not ~S.~@:>"
:arguments (uri options expected))))))))
(addtest (uris-root
:documentation
"Smoke test for the `scope->uri-and-options' function.")
uri->scope-and-options-smoke
(ensure-cases (uri-string expected-scope &optional expected-options)
'(;; From https://code.cor-lab.de/projects/rsb/wiki/URI_Schema
("" "/" ())
("spread:" "/" ((:spread :enabled t &inherit)
(t :enabled nil &inherit)))
("inprocess:" "/" ((:inprocess :enabled t &inherit)
(t :enabled nil &inherit)))
("spread://localhost:5555" "/" ((:spread :enabled t :host "localhost" :port 5555 &inherit)
(t :enabled nil &inherit)))
("inprocess://someotherhost" "/" ((:inprocess :enabled t :host "someotherhost" &inherit)
(t :enabled nil &inherit)))
("spread:/foo/bar" "/foo/bar" ((:spread :enabled t &inherit)
(t :enabled nil &inherit)))
("spread:?maxfragmentsize=10000" "/" ((:spread :enabled t :maxfragmentsize "10000" &inherit)
(t :enabled nil &inherit)))
;; Additional
("foo:/bla?bar=baz;awesome=no" "/bla" ((:foo :enabled t :bar "baz" :awesome "no" &inherit)
(t :enabled nil &inherit)))
("bar:" "/" ((:bar :enabled t &inherit)
(t :enabled nil &inherit)))
("bar://baz:20" "/" ((:bar :enabled t :host "baz" :port 20 &inherit)
(t :enabled nil &inherit)))
("bar://baz" "/" ((:bar :enabled t :host "baz" &inherit)
(t :enabled nil &inherit)))
("/?foo=5&bar=whoop" "/" ((t :foo "5" :bar "whoop" &inherit)))
;; Some illegal cases.
("#fragment" error)
("//host" error)
(":1234" error)
("//host:1234" error)
("?host=foo" error)
("?port=4444" error))
(let+ (((&flet do-it ()
(uri->scope-and-options (puri:parse-uri uri-string)))))
(case expected-scope
(error
(ensure-condition 'error (do-it)))
(t
(let+ (((&values scope options) (do-it)))
(ensure-same scope expected-scope
:test #'scope=
:report "~@<Expected scope ~S, not ~S.~@:>"
:arguments (expected-scope scope))
(ensure-same options expected-options
:test #'equalp
:report "~@<Expected options ~S, not ~S.~@:>"
:arguments (expected-options options))))))))
| 5,353 | Common Lisp | .lisp | 90 | 44.433333 | 118 | 0.36798 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 08ef30ae3c77479a565cfec35b79b43772a267c2b670723167afaecb9e8af1d4 | 25,170 | [
-1
] |
25,171 | package.lisp | open-rsx_rsb-cl/test/event-processing/package.lisp | ;;;; package.lisp --- Package definition for unit tests of the event-processing module.
;;;;
;;;; Copyright (C) 2011-2017 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:defpackage #:rsb.event-processing.test
(:use
#:cl
#:alexandria
#:let-plus
#:lift
#:rsb
#:rsb.event-processing
#:rsb.test)
(:documentation
"This package contains unit tests for the event-processing
module"))
(cl:in-package #:rsb.event-processing.test)
(deftestsuite event-processing-root (root)
()
(:documentation
"Root unit test suite for the event-processing module."))
;;; `mock-processor' mock class
(defclass mock-processor ()
((handled :initarg :handled
:type list
:accessor processor-handled
:initform '())))
(defmethod handle ((sink mock-processor) (data t))
(appendf (processor-handled sink) (list data)))
| 913 | Common Lisp | .lisp | 30 | 26.5 | 87 | 0.684211 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 872a550c5085e56f1f0ad7bf39b43ef45bd7fd7ab09a5068bc991b3259758623 | 25,171 | [
-1
] |
25,172 | processor-mixins.lisp | open-rsx_rsb-cl/test/event-processing/processor-mixins.lisp | ;;;; processor-mixins.lisp --- Unit tests for processor mixin classes.
;;;;
;;;; Copyright (C) 2013-2018 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.event-processing.test)
;;; `error-policy-mixin' test suite
(deftestsuite error-policy-mixin-root (event-processing-root)
((simple-processor (make-instance 'error-policy-mixin)))
(:documentation
"Test suite for the `error-policy-mixin' class."))
(defun error-policy-mixin.signaling-function (&optional recursive?)
"A function that unconditionally signals an error."
(restart-case
(error "~@<I like to signal.~@:>")
(continue (&optional condition)
(declare (ignore condition))
(when recursive?
(with-simple-restart (continue "Nested Continue")
(error "~@<Another error.~@:>")))
nil)))
(macrolet
((define-smoke-test (name &body call-form)
`(addtest (error-policy-mixin-root
:documentation
"Test basic error handling policies of the
`error-policy-mixin' class.")
,name
;; Error policy nil means to just unwind.
(setf (processor-error-policy simple-processor) nil)
(ensure-condition 'simple-error
,@call-form)
;; The error policy #'continue should prevent the error from
;; being signaled.
(setf (processor-error-policy simple-processor) #'continue)
,@call-form)))
(define-smoke-test smoke/function
(call-with-error-policy
simple-processor #'error-policy-mixin.signaling-function))
(define-smoke-test smoke/macro
(with-error-policy (simple-processor)
(error-policy-mixin.signaling-function)))
(define-smoke-test recursive-eror
(with-error-policy (simple-processor)
(error-policy-mixin.signaling-function t))))
;;; {error-policy,restart}-{dispatcher,handler}-mixin test suites
(defun error-policy+restart-mixins.signaling-handler (event)
"A handler that unconditionally signals an error."
(error "~@<I hate ~A.~@:>" event))
(macrolet
((define-error-policy+restart-mixins-tests (method name)
(let* ((error-policy-class-name
(symbolicate '#:error-policy- name '#:-mixin))
(error-policy-suite-name
(symbolicate error-policy-class-name '#:-root))
(restart-class-name
(symbolicate '#:restart- name '#:-mixin))
(restart-suite-name
(symbolicate restart-class-name '#:-root)))
`(progn
(deftestsuite ,error-policy-suite-name (event-processing-root)
()
(:documentation
,(format nil "Test suite for the `~(~A~)' class."
error-policy-class-name)))
(addtest (,error-policy-suite-name
:documentation
,(format nil "Smoke test for the `~(~A~)' class."
error-policy-class-name))
smoke
(let ((processor (make-instance (ensure-processor-class
'(error-policy-mixin
,error-policy-class-name
broadcast-processor)))))
(push #'error-policy+restart-mixins.signaling-handler
(handlers processor))
;; Error policy nil means to just unwind.
(setf (processor-error-policy processor) nil)
(ensure-condition 'simple-error
(handle processor (make-event "/" "bla")))
;; The error policy #'continue should prevent the error from being
;; signaled.
(setf (processor-error-policy processor) #'continue)
(ensure-same
(restart-case
(handle processor (make-event "/" "bla"))
(continue (&optional condition)
:continue-restart))
:continue-restart)))
(deftestsuite ,restart-suite-name (event-processing-root)
()
(:documentation
,(format nil "Test suite for the `~(~A~)' class."
restart-class-name)))
(addtest (,restart-suite-name
:documentation
,(format nil "Smoke test for the `~(~A~)' class."
restart-class-name))
smoke
(let ((processor (make-instance (ensure-processor-class
'(,restart-class-name
broadcast-processor)))))
(handler-bind
((error
(lambda (condition)
(let ((restart (find-restart 'continue)))
(ensure restart)
(ensure-same
,(format nil "Ignore the failures to ~A" method)
(princ-to-string restart)
:test #'search)))))
(handle processor (make-event "/" "bla")))))))))
(define-error-policy+restart-mixins-tests dispatch dispatcher)
(define-error-policy+restart-mixins-tests handle handler))
;;; `transform-mixin' tests
(deftestsuite rsb.event-processing.transform-mixin-root (event-processing-root)
()
(:documentation
"Unit tests for the `transform-mixin' processor mixin class.
See test suite for `transform!' generic function."))
(defclass transform-mock-processor (transform-mixin
mock-processor)
())
(addtest (rsb.event-processing.transform-mixin-root
:documentation
"Smoke test for the `transform-mixin' processor mixin
class.")
smoke
(ensure-cases (initargs objects expected)
`(;; Some invalid transforms.
((:transform :no-such-transform) (:does-not-matter) rsb.transform:transform-error)
((:transform (:no-such-transform)) (:does-not-matter) rsb.transform:transform-error)
((:transform ,#'1+) (:wrong-type) rsb.transform:transform-error)
;; These are valid
((:transform ,#'1+) (1 2 3) (2 3 4))
((:transform (,#'1+ ,(curry #'* 2))) (1 2 3) (3 5 7))
((:transform (,(curry #'* 2) ,#'1+)) (1 2 3) (4 6 8)))
(let+ (((&flet do-it ()
(let ((processor (apply #'make-instance
'transform-mock-processor initargs)))
(mapc (curry #'handle processor) objects)
(processor-handled processor)))))
(case expected
(rsb.transform:transform-error
(ensure-condition 'rsb.transform:transform-error (do-it)))
(t
(ensure-same (do-it) expected :test #'equal))))))
;;; `sink-dispatcher-mixin'
(deftestsuite rsb.event-processing.sink-dispatcher-mixin-root (event-processing-root)
()
(:documentation
"Unit test for the `sink-dispatcher-mixin' processor mixin class."))
(addtest (rsb.event-processing.sink-dispatcher-mixin-root
:documentation
"Smoke test for the `sink-dispatcher-mixin' processor mixin
class.")
smoke
(let+ ((dispatcher (make-instance 'sink-dispatcher-mixin))
((&flet subscribe (subject scope)
(notify dispatcher subject (subscribed (make-scope scope)))))
((&flet unsubscribe (subject scope)
(notify dispatcher subject (unsubscribed (make-scope scope)))))
((&flet dispatch (scope event)
(dispatch dispatcher (scope-and-event
(make-scope scope) event)))))
;; Simple scenario with two sinks.
(let* ((events1 '())
(handler1 (lambda (event) (push event events1)))
(events2 '())
(handler2 (lambda (event) (push event events2))))
(subscribe handler1 "/foo")
(subscribe handler2 "/foo/bar")
(dispatch "/" 1)
(ensure-same events1 '() :test #'equal)
(ensure-same events2 '() :test #'equal)
(dispatch "/foo" 2)
(ensure-same events1 '(2) :test #'equal)
(ensure-same events2 '() :test #'equal)
(dispatch "/foo/bar" 3)
(ensure-same events1 '(3 2) :test #'equal)
(ensure-same events2 '(3) :test #'equal)
(unsubscribe handler1 "/foo")
(dispatch "/foo/bar" 4)
(ensure-same events1 '(3 2) :test #'equal)
(ensure-same events2 '(4 3) :test #'equal))))
| 8,669 | Common Lisp | .lisp | 185 | 34.578378 | 94 | 0.560976 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | c5b61f0124bc2caa442f99852e4d98ee357726d57b99b0d48ec4ec95d1f8ed4a | 25,172 | [
-1
] |
25,173 | util.lisp | open-rsx_rsb-cl/test/event-processing/util.lisp | ;;;; util.lisp --- Unit tests for utility functions of the event-processing module.
;;;;
;;;; Copyright (C) 2011, 2012, 2013 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.event-processing.test)
(deftestsuite util-root (event-processing-root)
()
(:documentation
"Unit tests for the utility functions of the event-processing module."))
(addtest (util-root
:documentation
"Smoke test for the `merge-implementation-info' function.")
merge-implementation-infos-smoke
(ensure-cases (input expected)
'((() :implemented)
((:not-implemented) :not-implemented)
((:implemented) :implemented)
((:implemented :not-implemented) :not-implemented)
((:implemented :implemented) :implemented))
(let ((result (reduce #'merge-implementation-infos input)))
(ensure-same result expected
:test #'eq))))
| 1,001 | Common Lisp | .lisp | 23 | 38.043478 | 83 | 0.634121 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | dbe06e7c40904e4d2a8354dc75d3bc2622f40f7d265359bf3d8382d3c1105c99 | 25,173 | [
-1
] |
25,174 | protocol.lisp | open-rsx_rsb-cl/test/event-processing/protocol.lisp | ;;;; protocol.lisp --- Test for the protocol functions provided by the event-processing module.
;;;;
;;;; Copyright (C) 2017 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.event-processing.test)
(defclass mock-access-processor ()
((access :initarg :access
:reader processor-access)))
(defmethod access? ((processor mock-access-processor)
(part symbol)
(mode symbol))
(assoc-value (processor-access processor) (cons part mode) :test #'equal))
(addtest (event-processing-root
:documentation
"Smoke test for the `access?' generic function.")
access?/smoke
(let* ((processor1 (make-instance 'mock-access-processor
:access '(((:data . :read) . t))))
(processor2 (make-instance 'mock-access-processor
:access '(((:scope . :read) . t))))
(processors (list processor1 processor2)))
(ensure-same (access? processor1 :data :read) t)
(ensure-same (access? processor1 :data :write) nil)
(ensure-same (access? processor1 :scope :read) nil)
(ensure-same (access? processor1 :meta-data :read) nil)
(ensure-same (access? processor1 '(:data) :read) t)
(ensure-same (access? processor1 '(:scope) :read) nil)
(ensure-same (access? processor1 '(:data :scope) :read) t)
(ensure-same (access? processors :data :read) t)
(ensure-same (access? processors :scope :read) t)
(ensure-same (access? processors :meta-data :read) nil)))
| 1,667 | Common Lisp | .lisp | 32 | 44.34375 | 95 | 0.598894 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | bdf47dfe00d6c2ae39ed5f9d98e7e5101b7c906837b93b19e11793989b8ad463 | 25,174 | [
-1
] |
25,175 | in-route-configurator.lisp | open-rsx_rsb-cl/test/event-processing/in-route-configurator.lisp | ;;;; in-route-configurator.lisp --- Unit tests for the in-route-configurator class.
;;;;
;;;; Copyright (C) 2011-2017 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.event-processing.test)
(rsb.transport:register-transport
:mock
:schemas :mock
:wire-type 'string)
(defclass mock-connector (rsb.transport:connector
broadcast-processor)
()
(:metaclass rsb.transport:connector-class)
(:transport :mock)
(:direction :in-pull)
(:default-initargs
:schema :mock))
(deftestsuite in-route-configurator-root (event-processing-root)
((configurator (make-instance 'in-route-configurator
:scope "/foo/bar"
:direction :in-pull)))
(:function
(check-configurator (configurator scope direction configurator-filters processor-filters)
(ensure-same (configurator-scope configurator) (make-scope scope)
:test #'scope=)
(ensure-same (configurator-direction configurator) direction
:test #'eq)
(ensure-same (configurator-filters configurator) configurator-filters
:test #'equal)
(ensure-same (processor-filters
(configurator-processor configurator))
processor-filters
:test #'equal)))
(:documentation
"Root test suite for the `in-route-configurator-root' class."))
(addtest (in-route-configurator-root
:documentation
"Test the required state transitions and updates when adding
and removing filters to an `in-route-configurator' instance.")
adding/removing-filters
(let ((filter (make-instance 'rsb.filter:conjoin-filter)))
;; Adding and removing a filter should not have an effect when
;; there are no connectors.
(notify configurator filter :filter-added)
(check-configurator configurator "/foo/bar" :in-pull
(list filter) nil)
(notify configurator filter :filter-removed)
(check-configurator configurator "/foo/bar" :in-pull nil nil)
;; However, when there is a connector, the filter should get
;; propagated to the processor.
(push (make-instance 'mock-connector)
(configurator-connectors configurator))
(notify configurator filter :filter-added)
(check-configurator configurator "/foo/bar" :in-pull
(list filter) (list filter))
(notify configurator filter :filter-removed)
(check-configurator configurator "/foo/bar" :in-pull nil nil)))
| 2,570 | Common Lisp | .lisp | 58 | 36.568966 | 92 | 0.671463 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 1e7ce97c7d80b521fbc9018427d97f3fe88279ada5219abea20c846fd0076912 | 25,175 | [
-1
] |
25,176 | scope-trie.lisp | open-rsx_rsb-cl/test/event-processing/scope-trie.lisp | ;;;; scope-trie.lisp --- Tests for the scope-trie and sink-scope-trie classes.
;;;;
;;;; Copyright (C) 2015, 2016 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.event-processing.test)
;;; Utilities.
(defparameter *scope-trie-test-a-few-scopes*
(mapcar #'make-scope '("/a/b/c" "/a/b/c" "/a/e/c" "/a/b" "/a" "/")))
(defparameter *scope-trie-test-lots-of-scopes*
(let ((result '()))
(map-permutations (lambda (components)
(push (make-scope components) result))
'("a" "b" "c" "d" "e"))
result))
(defun make-filled-scope-trie (&optional
(scopes *scope-trie-test-a-few-scopes*))
(let+ ((trie (make-scope-trie))
((&flet add-scope (scope)
(scope-trie-update
(lambda (value valuep)
(values (list* (scope-string scope) (when valuep value)) t))
scope trie))))
;; Add some scopes.
(mapc #'add-scope scopes)
trie))
;;; `scope-trie'
(deftestsuite event-processing-scope-trie-root (event-processing-root)
()
(:documentation
"Test suite for the `scope-trie' data structure."))
(addtest (event-processing-scope-trie-root
:documentation
"Smoke test for the `scope-trie' data structure.")
smoke
;; Order of additions and removals must not matter.
(map-permutations
(lambda (scopes)
(let+ ((trie (make-scope-trie))
((&flet add-scope (scope)
(scope-trie-update
(lambda (value valuep)
(values (list* (scope-string scope) (when valuep value)) t))
scope trie)))
((&flet check-empty ()
(dolist (scope scopes)
(ensure-same (nth-value 1 (scope-trie-get scope trie)) nil)))))
;; We repeat the process to ensure that deleting all values
;; restores the initial state and that the restored initial
;; state permits add values again. There was a bug regarding
;; removing the value associated to the root scope at some
;; point.
(loop :repeat 2 :do
;; Initially empty/empty again.
(check-empty)
;; Add some entries.
(mapc #'add-scope scopes)
;; Check stored entries.
(dolist (scope scopes)
(let* ((count (count scope *scope-trie-test-a-few-scopes*
:test #'scope=))
(expected (make-list count
:initial-element (scope-string scope))))
(ensure-same (scope-trie-get scope trie) (values expected t)
:test #'equal)))
;; Remove all entries.
(mapc (rcurry #'scope-trie-rem trie) scopes))))
*scope-trie-test-a-few-scopes*))
(addtest (event-processing-scope-trie-root
:documentation
"Smoke test for the `scope-trie-map' function.")
scope-trie-map/smoke
(let ((trie (make-filled-scope-trie)))
(ensure-cases (scope expected)
'(("/" (("/")))
("/b" (("/")))
("/a" (("/") ("/a/")))
("/a/b" (("/") ("/a/") ("/a/b/")))
("/a/b/c" (("/") ("/a/") ("/a/b/") ("/a/b/c/" "/a/b/c/"))))
(let ((scope (make-scope scope))
(values '()))
(scope-trie-map (lambda (scope value)
(ensure-same scope (first value) :test #'scope=)
(push value values))
scope trie)
(ensure-same (reverse values) expected :test #'equal)))))
(defun cleanup-test (thunk)
(let* ((count 100)
(random-scope (random-scope :length (random-integer 0 4)))
(queue (map-into (make-list count) random-scope))
(trie (make-scope-trie))
(thunk (ensure-function thunk)))
(loop :for i :below 200000
:for remove = (pop queue)
:for add = (funcall random-scope) :do
(appendf queue (list add))
(ensure-same (length queue) count)
(setf (scope-trie-get add trie) i)
(funcall thunk trie remove))))
(addtest (event-processing-scope-trie-root
:documentation
"Make sure that removing entries from the `scope-trie' via
`scope-trie-rem' cleans everything up.")
scope-trie-rem/cleanup
(cleanup-test (lambda (trie remove) (scope-trie-rem remove trie))))
(addtest (event-processing-scope-trie-root
:documentation
"Make sure that removing entries from the `scope-trie' via
`scope-trie-update' cleans everything up.")
scope-trie-update/cleanup
(cleanup-test (lambda (trie remove)
(scope-trie-update
(lambda (value value?)
(declare (ignore value value?))
(values nil nil))
remove trie))))
(defun %scope-trie-test-make-adder (trie scopes i)
(named-lambda adder ()
(sleep (+ 0.001 (random 0.0001)))
(loop :for scope :in scopes :do
(scope-trie-update
(lambda (value valuep)
(values (list* i (when valuep value)) t))
scope trie))))
(defun %scope-trie-test-make-remover (trie scopes i)
(named-lambda remover ()
(loop :for scope :in scopes :do
(scope-trie-update (lambda (value value?)
(declare (ignore value?))
(let ((new (remove i value)))
(values new new)))
scope trie))))
(addtest (event-processing-scope-trie-root
:documentation
"Multi-threaded stress test for the `scope-trie' data
structure exercising concurrent insertions.")
stress.1
(loop :repeat 1000 :do
(let ((scopes *scope-trie-test-lots-of-scopes*)
(thread-count 3)
(trie (make-scope-trie)))
;; Run concurrent insertions.
(mapc #'bt:join-thread
(mapcar (compose #'bt:make-thread
(curry #'%scope-trie-test-make-adder
trie scopes))
(iota thread-count)))
;; Check expected number of items in each value.
(ensure-same (reduce #'+ scopes
:key (lambda (scope)
(length (scope-trie-get scope trie))))
(* thread-count (length scopes))))))
(addtest (event-processing-scope-trie-root
:documentation
"Multi-threaded stress test for the `scope-trie' data
structure exercising concurrent insertions and deletions.")
stress.2
(loop :repeat 1000 :do
(let ((scopes *scope-trie-test-lots-of-scopes*)
(thread-count 3)
(trie (make-scope-trie)))
;; Run concurrent insertions and deletions.
(mapc #'bt:join-thread
(mapcar
(lambda (i)
(let ((adder (%scope-trie-test-make-adder
trie scopes i))
(remover (%scope-trie-test-make-remover
trie scopes i)))
(bt:make-thread (lambda ()
(funcall adder)
(funcall remover)))))
(iota thread-count)))
;; Check that all entries have empty values after all
;; add-then-remove actions are done.
(ensure (every (lambda (scope)
(null (scope-trie-get scope trie)))
scopes)))))
(addtest (event-processing-scope-trie-root
:documentation
"Multi-threaded stress test for the `scope-trie' data
structure exercising concurrent insertions, deletions and
queries.")
stress.3
(let+ ((count 1000000)
(scope (make-scope '("a" "b" "c" "d" "e")))
(trie (let ((trie (make-filled-scope-trie)))
(setf (scope-trie-get scope trie)
(make-list count :initial-element :foo))
trie))
((&flet adder ()
(loop :repeat count :do
(scope-trie-update
(lambda (value value?)
(values (list* :foo (when value? value)) t))
scope trie))))
((&flet remover ()
(loop :repeat count :do
(scope-trie-update
(lambda (value value?)
(let ((new (when value? (rest value))))
(values new new)))
scope trie))))
;; "Background" threads concurrently add and remove entries.
(threads (mapcar #'bt:make-thread (list #'adder #'adder #'remover))))
(unwind-protect
;; Foreground thread queries items at the same time.
(loop :repeat (* 3 count) :do
(scope-trie-map (lambda (scope value)
(declare (ignore scope value)))
scope trie))
(mapc #'bt:join-thread threads))
;; Check result of concurrent adding and removing.
(ensure-same (length (scope-trie-get scope trie)) (* 2 count))))
;;; `sink-scope-trie'
(deftestsuite event-processing-sink-scope-trie-root (event-processing-root)
()
(:documentation
"Test suite for the `sink-scope-trie' class."))
(addtest (event-processing-sink-scope-trie-root
:documentation
"Smoke test for the `sink-scope-trie' data structure.")
smoke
(let+ ((trie (make-sink-scope-trie))
((&flet add-sink (scope)
(sink-scope-trie-add trie scope :foo)))
((&flet remove-sink (scope)
(sink-scope-trie-remove trie scope :foo))))
(mapc #'add-sink *scope-trie-test-a-few-scopes*)
(mapc #'remove-sink *scope-trie-test-a-few-scopes*)))
| 9,876 | Common Lisp | .lisp | 230 | 31.482609 | 80 | 0.540861 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 6561fd60b4d061b4ae1eae7f0ede16d541d6c8103673eea6f921f208f9800eb5 | 25,176 | [
-1
] |
25,177 | package.lisp | open-rsx_rsb-cl/test/transform/package.lisp | ;;;; package.lisp --- Package definition for unit tests of the transform module.
;;;;
;;;; Copyright (C) 2014, 2015, 2016 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:defpackage #:rsb.transform.test
(:use
#:cl
#:alexandria
#:let-plus
#:more-conditions
#:lift
#:rsb
#:rsb.transform
#:rsb.test)
(:documentation
"This package contains unit tests for the transform module"))
(cl:in-package #:rsb.transform.test)
(deftestsuite rsb.transform-root (root)
()
(:documentation
"Root unit test suite for the transform module."))
(defun call-with-transform-checking-thunk
(thunk transform-spec event-spec)
"Call THUNK with a function as the sole argument, that
1. Constructs a transform according to TRANSFORM-SPEC
2. Constructs an `access-checking-event' according to EVENT-SPEC
3. Transforms the event using the transform
4. Returns the transformed event"
(let+ (((&flet check (funcall?)
(let+ ((transform (apply #'make-transform
(ensure-list transform-spec)))
(event (apply #'make-access-checking-event-for-processor
transform event-spec))
((&flet do-it ()
(with-access-checking ()
(if funcall?
(funcall transform event)
(transform! transform event))))))
(funcall thunk #'do-it)))))
(check nil)
(check t)))
| 1,554 | Common Lisp | .lisp | 42 | 28.547619 | 80 | 0.604651 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | a25e1727863c9153ec90473924b126bbdfd561d0a5efe8826b19dd19be1f7416 | 25,177 | [
-1
] |
25,178 | protocol.lisp | open-rsx_rsb-cl/test/transform/protocol.lisp | ;;;; protocol.lisp --- Unit tests for the protocol provided by the transform module.
;;;;
;;;; Copyright (C) 2013, 2014, 2015 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.transform.test)
(deftestsuite rsb.transform.transform!-root (rsb.transform-root)
()
(:documentation
"Unit tests for the `transform!' generic function."))
(addtest (rsb.transform.transform!-root
:documentation
"Test default behavior of the `transform!' generic
function.")
default-behavior
(ensure-cases (transform object expected)
`(;; Some invalid transforms.
(:no-such-transform :does-not-matter transform-error)
((:no-such-transform) :does-not-matter transform-error)
(,#'1+ :wrong-type transform-error)
;; These are valid.
(,#'1+ 1 2)
((,#'1+ ,(curry #'* 2)) 1 3)
((,(curry #'* 2) ,#'1+) 1 4))
(let+ (((&flet do-it ()
(transform! transform object))))
(case expected
(transform-error (ensure-condition 'transform-error (do-it)))
(t (ensure-same (do-it) expected))))))
(addtest (rsb.transform.transform!-root
:documentation
"Test restarts established by default methods on the
`transform!' generic function.")
restarts
(ensure-cases (restart expected)
'((continue 1)
((use-value 2) 2))
(handler-bind
((error (lambda (condition)
(let+ (((name &rest args) (ensure-list restart))
(restart (find-restart name)))
;; Ensure it is there.
(ensure restart)
;; Ensure it prints.
(ensure (typep (princ-to-string restart) 'string))
;; Ensure it works.
(apply #'invoke-restart restart args)))))
(ensure-same (transform! (curry #'error "~@<I hate ~A~@:>") 1)
expected))))
(deftestsuite rsb.transform.make-transform-root (rsb.transform-root)
()
(:documentation
"Unit tests for the `make-transform' generic function."))
(addtest (rsb.transform.make-transform-root
:documentation
"Smoke test for the `make-transform' generic function.")
smoke
(ensure-cases (spec expected)
'((:no-such-transform transform-creation-error))
(let+ (((&flet do-it ()
(apply #'make-transform (ensure-list spec)))))
(case expected
(transform-creation-error
(ensure-condition transform-creation-error (do-it)))
(t
(do-it))))))
| 2,725 | Common Lisp | .lisp | 66 | 32.69697 | 84 | 0.568783 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 5d114ecefc4fcee3d48b2722d90fb6b507c92d8666bc24108a1c59c71c4dc456 | 25,178 | [
-1
] |
25,179 | drop-payload.lisp | open-rsx_rsb-cl/test/transform/drop-payload.lisp | ;;;; drop-payload.lisp --- Unit tests for the drop-payload transform.
;;;;
;;;; Copyright (C) 2011-2016 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.transform.test)
(deftestsuite rsb.transform.drop-payload-root (rsb.transform-root)
()
(:documentation
"Unit tests for the `drop-payload' transform."))
(addtest (rsb.transform.drop-payload-root
:documentation
"Smoke test for the `drop-payload' transform.")
smoke
(call-with-transform-checking-thunk
(lambda (do-it)
(ensure-same (event-data (funcall do-it)) +dropped-payload+))
:drop-payload (list "/" 5)))
| 656 | Common Lisp | .lisp | 18 | 32.888889 | 69 | 0.697161 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | e18da96e7f1839e0c725fa96d1bc0e5af296dd94a113c7e602148a376b32d9f9 | 25,179 | [
-1
] |
25,180 | adjust-timestamps.lisp | open-rsx_rsb-cl/test/transform/adjust-timestamps.lisp | ;;;; adjust-timestamps.lisp --- Unit tests for the adjust-timestamps transform.
;;;;
;;;; Copyright (C) 2015, 2016 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.transform.test)
(deftestsuite rsb.transform.adjust-timestamps-root (rsb.transform-root)
()
(:documentation
"Test suite for the `adjust-timestamps' transform."))
(addtest (rsb.transform.adjust-timestamps-root
:documentation
"Test constructing `adjust-timestamps' instances.")
construct
(ensure-cases (initargs expected)
`(;; Some invalid cases.
((:adjustments 1) transform-creation-error)
((:adjustments :foo) transform-creation-error)
((:adjustments (:foo)) transform-creation-error)
((:adjustments ((:foo))) transform-creation-error)
((:adjustments ((:create (:copy)))) transform-creation-error)
((:adjustments ((:create (+)))) transform-creation-error)
((:adjustments ((:create (+ 1)))) transform-creation-error)
;; These are OK.
(() t)
((:adjustments ()) t)
((:adjustments ((:create :now))) t)
((:adjustments ((:create ,(local-time:now)))) t)
((:adjustments ((:create ,(local-time:now)) (:send :now))) t)
((:adjustments ((:send (:copy :create)))) t)
((:adjustments ((:send (+ :create 5)))) t)
((:adjustments ((:send (+ (+ :create -1) 5)))) t)
((:adjustments ((:send :self))) t))
(flet ((do-it ()
(apply #'make-transform :adjust-timestamps initargs)))
(case expected
(transform-creation-error
(ensure-condition 'transform-creation-error (do-it)))
(t
(do-it))))))
(addtest (rsb.transform.adjust-timestamps-root
:documentation
"Smoke test for the `adjust-timestamps' transform.")
smoke
(ensure-cases (adjustments expected)
`(;; Some invalid cases.
(((:copied :no-such-timestamp)) error)
;; These are OK.
(()
(:create))
(((:fresh ,(local-time:now)))
(:create :fresh))
(((:copied :now))
(:create :copied))
(((:copied (:copy :create)))
(:create :copied))
(((:copied-1 :now) (:copied-2 :copied-1))
(:create :copied-1 :copied-2))
(((:adjusted (+ :create 5)))
(:create :adjusted))
(((:create (+ :self -1)))
(:create)))
(call-with-transform-checking-thunk
(lambda (do-it)
(case expected
(error (ensure-condition 'error (funcall do-it)))
(t (let ((result (funcall do-it)))
(dolist (expected expected)
(ensure (typep (timestamp result expected)
'local-time:timestamp)))))))
(list :adjust-timestamps :adjustments adjustments)
(list "/" 5))))
(addtest (rsb.transform.adjust-timestamps-root
:documentation
"Test printing `adjust-timestamps' instances.")
print
(let ((transform (make-transform :adjust-timestamps
:adjustments '((:create (+ :self 1))
(:copy-of-send :send)))))
(ensure (search "CREATE ← (+ SELF 1)" (princ-to-string transform)))
(ensure (search "COPY-OF-SEND ← SEND" (princ-to-string transform)))))
| 3,805 | Common Lisp | .lisp | 81 | 37.938272 | 92 | 0.503512 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 31841d55326687330f05a607382d0d54a96226a06fa800412ff4bfc9b3046a5e | 25,180 | [
-1
] |
25,181 | prefix-scope.lisp | open-rsx_rsb-cl/test/transform/prefix-scope.lisp | ;;;; prefix-scope.lisp --- Unit tests for the prefix-scope transform.
;;;;
;;;; Copyright (C) 2015, 2016 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.transform.test)
(deftestsuite rsb.transform.prefix-scope-root (rsb.transform-root)
()
(:documentation
"Unit tests for the `prefix-scope' transform."))
(addtest (rsb.transform.prefix-scope-root
:documentation
"Test constructing `prefix-scope' instances.")
construct
(ensure-condition transform-creation-error
(make-transform :prefix-scope))
(ensure-condition transform-creation-error
(make-transform :prefix-scope :prefix 1)))
(addtest (rsb.transform.prefix-scope-root
:documentation
"Smoke test for the `prefix-scope' transform.")
smoke
(ensure-cases (prefix event-scope expected)
'(("/" "/" "/")
("/" "/foo" "/foo")
("/" "/foo/bar" "/foo/bar")
("/baz" "/" "/baz/")
("/baz" "/foo" "/baz/foo")
("/baz" "/foo/bar" "/baz/foo/bar")
("/baz/fez" "/" "/baz/fez/")
("/baz/fez" "/foo" "/baz/fez/foo")
("/baz/fez" "/foo/bar" "/baz/fez/foo/bar"))
(call-with-transform-checking-thunk
(lambda (do-it)
(ensure-same expected (event-scope (funcall do-it)) :test #'scope=))
(list :prefix-scope :prefix prefix)
(list event-scope ""))))
(addtest (rsb.transform.prefix-scope-root
:documentation
"Test printing `prefix-scope' instances.")
print
(let ((transform (make-transform :prefix-scope :prefix "/foo")))
(ensure (search "/foo" (princ-to-string transform)))))
| 1,714 | Common Lisp | .lisp | 43 | 34.255814 | 75 | 0.602286 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 8a1f6b57c55b45db9182b14ad367b76fffc430d768f59a04366e6a76acf3372b | 25,181 | [
-1
] |
25,182 | package.lisp | open-rsx_rsb-cl/test/patterns/package.lisp | ;;;; package.lisp --- Package definition for unit tests of the patterns module.
;;;;
;;;; Copyright (C) 2014, 2015 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:defpackage #:rsb.patterns.test
(:use
#:cl
#:alexandria
#:let-plus
#:lift
#:rsb
#:rsb.patterns
#:rsb.test)
(:export
#:patterns-root)
(:documentation
"This package contains unit tests for the patterns module."))
(cl:in-package #:rsb.patterns.test)
(deftestsuite patterns-root (root)
()
(:documentation
"Root unit test suite for the patterns module."))
| 597 | Common Lisp | .lisp | 23 | 22.869565 | 79 | 0.690813 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | a096ee8e3ffe0b12af44edc3a63126440054d1403f9282981dbf3dc804c281ff | 25,182 | [
-1
] |
25,183 | protocol.lisp | open-rsx_rsb-cl/test/patterns/protocol.lisp | ;;;; protocol.lisp --- Tests for the protocol of the patterns module.
;;;;
;;;; Copyright (C) 2015, 2021 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.patterns.test)
(deftestsuite rsb-patterns-protocol-root (patterns-root)
()
(:documentation
"Unit tests for the protocol functions of the patterns module."))
(defclass mock-composite-participant/protocol (child-container-mixin) ())
(addtest (rsb-patterns-protocol-root
:documentation
"Smoke test for the `participant-child' generic function.")
participant-child/smoke
(let+ ((participant (make-instance 'mock-composite-participant/protocol))
((&flet do-it (&rest args)
(apply #'participant-child participant :no-such :mock args))))
;; Try non-existing child, returning nil.
(ensure-null (do-it))
(ensure-null (do-it :if-exists nil)) ; ignored
(ensure-null (do-it :detach? nil)) ; ignored
(ensure-null (do-it :if-does-not-exist nil))
;; Try non-existing child, signaling an error.
(ensure-condition 'no-such-child-error
(do-it :if-does-not-exist 'error))
(ensure-condition 'no-such-child-error
(do-it :if-does-not-exist #'error))))
(addtest (rsb-patterns-protocol-root
:documentation
"Test `use-value' restart established by the
`participant-child' generic function.")
participant-child/restart
(let ((participant (make-instance 'mock-composite-participant/protocol)))
(handler-bind ((no-such-child-error
(lambda (condition)
(declare (ignore condition))
(let ((restart (find-restart 'use-value)))
(ensure (stringp (princ-to-string restart)))
(invoke-restart restart :replacement)))))
(ensure-same (participant-child participant :no-such :mock
:if-does-not-exist 'error)
:replacement))))
(addtest (rsb-patterns-protocol-root
:documentation
"Smoke test for the setf `participant-child' generic
function.")
setf-participant-child/smoke
(let+ ((participant (make-instance 'mock-composite-participant/protocol))
(child1 (make-participant :mock "/" :introspection? nil))
(child2 (make-participant :mock "/" :introspection? nil))
(child3 (make-participant :mock "/" :introspection? nil))
((&flet put-it (child &rest args)
(apply #'(setf participant-child) child participant :foo :mock
args)))
((&flet get-it (&rest args)
(apply #'participant-child participant :foo :mock args))))
;; Install and replace child. Replacing a child with itself should
;; not detach.
(ensure-same (put-it child1) child1 :test #'eq)
(ensure-same (get-it) child1 :test #'eq)
(ensure-same (put-it child1) child1 :test #'eq)
(ensure-same (get-it) child1 :test #'eq)
(ensure-same (mock-participant-state child1) :attached)
(ensure-same (put-it child2) child2 :test #'eq)
(ensure-same (get-it) child2 :test #'eq)
(ensure-same (mock-participant-state child1) :detached)
;; Replace child with :supersede.
(ensure-same (put-it child1 :if-exists :supersede) child1 :test #'eq)
(ensure-same (get-it) child1 :test #'eq)
(ensure-same (mock-participant-state child2) :detached)
;; Remove child.
(ensure-same (put-it nil) nil :test #'eq)
(ensure-same (get-it) nil :test #'eq)
;; Replace child without detaching it.
(ensure-same (put-it child3 :if-exists :supersede) child3
:test #'eq)
(ensure-same (put-it child1 :if-exists :supersede :detach? nil) child1
:test #'eq)
(ensure-same (mock-participant-state child3) :attached)
;; Signal an error for duplicate child.
(ensure-same (put-it child3 :if-exists :supersede) child3 :test #'eq)
(ensure-condition 'child-exists-error
(put-it child2 :if-exists 'error))
(ensure-same (get-it) child3 :test #'eq)
(ensure-same (mock-participant-state child3) :attached)))
(addtest (rsb-patterns-protocol-root
:documentation
"Use `continue' restart established established by the setf
`participant-child' generic function.")
setf-participant-child/restart
(let ((parent (make-instance 'mock-composite-participant/protocol))
(child1 (make-participant :mock "/"))
(child2 (make-participant :mock "/")))
(handler-bind ((child-exists-error
(lambda (condition)
(declare (ignore condition))
(let ((restart (find-restart 'continue)))
(ensure (stringp (princ-to-string restart)))
(invoke-restart restart)))))
(setf (participant-child parent :foo :mock) child1
(participant-child parent :foo :mock :if-exists 'error) child2))
(ensure-same (participant-child parent :foo :mock) child2 :test #'eq)))
(addtest (rsb-patterns-protocol-root
:documentation
"Smoke test for the `make-child-scope' generic function.")
make-child-scope/smoke
(ensure-cases (which expected)
`((nil "/parent")
(:foo "/parent/foo")
("foo" "/parent/foo")
("Foo" "/parent/Foo")
("FOO" "/parent/FOO")
(,(make-scope "/foo") "/parent/foo")
(,(make-scope "/Foo") "/parent/Foo")
(,(make-scope "/FOO") "/parent/FOO")
(,(puri:uri "socket:/foo?baz=fez") ,(puri:uri "socket:/parent/foo/?baz=fez")))
(let+ (((&flet do-it ()
(let ((parent (make-participant :mock "/parent")))
(make-child-scope parent which :listener)))))
(ensure-same (do-it) expected
:test (lambda (left right)
(etypecase left
(scope (scope= left right))
(puri:uri (puri:uri= left right))))))))
(addtest (rsb-patterns-protocol-root
:documentation
"Smoke test for the `make-child-participant' generic function.")
make-child-participant/smoke
(ensure-cases (initargs expected-kind expected-scope)
'(;; Simplest case.
(() :mock "/parent/foo")
;; Supply scope.
((:scope "/differentscope") :mock "/differentscope"))
(let* ((parent (make-participant :mock "/parent"))
(child (apply #'make-child-participant parent "foo" :mock
initargs)))
(ensure-same (participant-kind child) expected-kind)
(ensure-same (participant-scope child) expected-scope :test #'scope=))))
| 7,010 | Common Lisp | .lisp | 139 | 41.280576 | 86 | 0.590159 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 11b76da39a46f5278fe897d8e350a5a57c13e0fd4084f5ff3031c39be7561bfe | 25,183 | [
-1
] |
25,184 | mixins.lisp | open-rsx_rsb-cl/test/patterns/mixins.lisp | ;;;; mixins.lisp --- Unit tests for mixin classes in the pattern module.
;;;;
;;;; Copyright (C) 2015, 2017, 2018 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.patterns.test)
;;; `composite-participant-mixin'
(defclass mock-composite-participant/composite-participant-mixin
(composite-participant-mixin
child-container-mixin
print-items:print-items-mixin)
())
(deftestsuite composite-participant-mixin-root (patterns-root)
()
(:documentation
"Unit tests for the `composite-participant-mixin' class."))
(addtest (composite-participant-mixin-root
:documentation
"Smoke test for the `print-items:print-items' method
specialized on `composite-participant-mixin'.")
print/smoke
(let ((participant
(make-instance 'mock-composite-participant/composite-participant-mixin)))
(ensure (search "(0)" (princ-to-string participant)))
(setf (participant-child participant :foo :mock)
(make-participant :mock "/foo"))
(ensure (search "(1)" (princ-to-string participant)))))
(addtest (composite-participant-mixin-root
:documentation
"Smoke test for the `detach' method specialized on
`composite-participant-mixin'.")
detach/smoke
(let ((parent
(make-instance 'mock-composite-participant/composite-participant-mixin))
(child (make-participant :mock "/foo")))
(setf (participant-child parent :foo :mock) child)
(ensure-same (mock-participant-state child) :attached)
(detach parent)
(ensure-same (mock-participant-state child) :detached)))
(defclass mock-cleanup-composite-participant (participant
composite-participant-mixin)
((children :initarg :children
:accessor participant-children)))
(defmethod shared-initialize :after
((instance mock-cleanup-composite-participant)
(slot-names t)
&key)
(error "something went wrong"))
(addtest (composite-participant-mixin-root
:documentation
"Ensure that `detach' is called on all already registered
child participants when an error is signaled during
initialization.")
failed-construction-cleanup
;; Make sure that `detach' is called for all children that were
;; already registered at the time of the error.
(let ((children (list (make-participant :mock "/compositeparticipantmixinroot/child"))))
(ensure-condition 'error
(make-instance 'mock-cleanup-composite-participant
:scope "/compositeparticipantmixinroot"
:children children))
(ensure (every (lambda (child)
(eq (mock-participant-state child) :detached))
children))))
;;; `child-container-mixin'
(deftestsuite child-container-mixin-root (patterns-root)
()
(:documentation
"Unit tests for the `child-container-mixin' class."))
(addtest (child-container-mixin-root
:documentation
"Smoke test for the `participant-child' and setf
`participant-child' methods specialized on
`child-container-mixin'.")
participant-child/smoke
(let ((parent (make-instance 'child-container-mixin))
(child (make-participant :mock "/foo")))
(ensure-null (participant-child parent :no-such :no-such))
(setf (participant-child parent :foo :mock) child)
(ensure-same (participant-child parent :foo :mock) child)
(setf (participant-child parent :foo :mock) nil)
(ensure-null (participant-child parent :foo :mock))))
;;; `configuration-inheritance-mixin'
(defclass mock-composite-participant/configuration-inheritance-mixin
(configuration-inheritance-mixin
participant)
())
(deftestsuite configuration-inheritance-mixin-root (patterns-root)
()
(:documentation
"Unit tests for the `configuration-inheritance-mixin' class."))
(addtest (configuration-inheritance-mixin-root
:documentation
"Smoke test for the `make-child-initargs' method specialized
on the `configuration-inheritance-mixin' class.")
make-child-initargs/smoke
(ensure-cases (parent-initargs override-initargs expected)
'(;; Everything in parent initargs, no override initargs.
((:transports ((:socket :enabled t :port 1020))
:converters (:foo)
:transform 1+
:introspection? t)
()
((:transports . ((:inprocess :enabled t)
(:socket :enabled t :port 1020)))
(:converters . (:foo))
(:transform . 1+)
(:introspection? . t)))
;; Some override initargs.
((:transports ((:socket :enabled t :port 1020))
:converters (:foo)
:transform 1+
:introspection? t)
(:transform 1-
:introspection? nil)
((:transports . ((:inprocess :enabled t)
(:socket :enabled t :port 1020)))
(:converters . (:foo))
(:transform . 1-)
(:introspection? . nil))))
(let* ((class (find-class 'mock-composite-participant/configuration-inheritance-mixin))
(parent (progn
(c2mop:finalize-inheritance class)
(apply #'make-participant-using-class
class (c2mop:class-prototype class)
(make-scope "/foo") parent-initargs)))
(result (apply #'make-child-initargs parent :foo :mock
override-initargs))
(result (plist-alist (remove-from-plist result :error-policy))))
(ensure-same result expected :test (rcurry #'set-equal :test #'equal)))))
(addtest (configuration-inheritance-mixin-root
:documentation
"Ensure that the current value of `*configuration*' does not
affect child participants created using
`configuration-inheritance-mixin'.")
no-*configuration*-leakage
(let* ((class (find-class 'mock-composite-participant/configuration-inheritance-mixin))
(parent (progn
(c2mop:finalize-inheritance class)
(make-participant-using-class
class (c2mop:class-prototype class)
(make-scope "/foo"))))
;; If `*configuration*' leaks into the
;; `make-child-participant' call, an error will be signaled
;; since the requested transport does not exist.
(*configuration* '(((:transport :does-not-exist :enabled) . t))))
(with-active-participant
(nil (make-child-participant parent :foo :listener)))))
;;; `lazy-child-making-mixin'
(defclass mock-composite-participant/lazy-child-making-mixin
(lazy-child-making-mixin
child-container-mixin
participant)
((args :accessor mock-participant-args)))
(defmethod make-child-participant
((participant mock-composite-participant/lazy-child-making-mixin)
(which t)
(kind t)
&rest initargs &key)
(setf (mock-participant-args participant) (list* which kind initargs))
(make-participant :mock "/foo"))
(deftestsuite lazy-child-making-mixin-root (patterns-root)
()
(:documentation
"Unit tests for the `lazy-child-making-mixin' class."))
(addtest (lazy-child-making-mixin-root
:documentation
"Smoke test for the `participant-child' method specialized
on `lazy-child-making-mixin'.")
participant-child/smoke
(let ((parent (make-instance 'mock-composite-participant/lazy-child-making-mixin
:scope "/bar")))
(participant-child parent :foo :mock :if-does-not-exist :create)
(ensure-same (mock-participant-args parent) '(:foo :mock))))
| 7,882 | Common Lisp | .lisp | 174 | 36.804598 | 99 | 0.642615 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | a3ef787ae330e6c7db4d043aa88ee1b82539f98449d67d0b907b79dd917aef42 | 25,184 | [
-1
] |
25,185 | package.lisp | open-rsx_rsb-cl/test/patterns/reader/package.lisp | ;;;; package.lisp --- Package definition for unit tests of the patterns.reader module.
;;;;
;;;; Copyright (C) 2018 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:defpackage #:rsb.patterns.reader.test
(:use
#:cl
#:lift
#:rsb
#:rsb.patterns.reader
#:rsb.test
#:rsb.patterns.test)
(:export
#:patterns-reader-root)
(:documentation
"This package contains unit tests for the patterns.reader
module."))
(cl:in-package #:rsb.patterns.reader.test)
(deftestsuite patterns-reader-root (patterns-root)
()
(:documentation
"Root unit test suite for the patterns.reader module."))
| 652 | Common Lisp | .lisp | 23 | 25.26087 | 86 | 0.709003 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 0355eadc9e3822a7c36d9c7cc773e8082d5203f21e82730bc4fc4d469b5ae410 | 25,185 | [
-1
] |
25,186 | reader.lisp | open-rsx_rsb-cl/test/patterns/reader/reader.lisp | ;;;; reader.lisp --- Unit tests for the reader class.
;;;;
;;;; Copyright (C) 2011-2019 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.patterns.reader.test)
(deftestsuite reader-root (root
participant-suite)
()
(:documentation
"Unit tests for the `reader' class."))
(define-basic-participant-test-cases reader
'("/rsbtest/reader/construction"
()
"/rsbtest/reader/construction")
'("/rsbtest/reader/construction"
(:transports ((:inprocess &inherit)))
"/rsbtest/reader/construction")
'("/rsbtest/reader/construction"
(:transports ((t &inherit) (:inprocess &inherit)))
"/rsbtest/reader/construction")
'("/rsbtest/reader/construction"
(:converters ((t . :foo)))
"/rsbtest/reader/construction")
`("/rsbtest/reader/construction"
(:transform ,#'1+)
"/rsbtest/reader/construction")
`("/rsbtest/reader/construction"
(:parent ,*simple-parent*)
"/rsbtest/reader/construction")
'("/rsbtest/reader/construction"
(:introspection? nil)
"/rsbtest/reader/construction")
'("/rsbtest/reader/construction"
(:introspection? t)
"/rsbtest/reader/construction")
'("inprocess:/rsbtest/reader/construction"
()
"/rsbtest/reader/construction")
`("inprocess:/rsbtest/reader/construction"
(:error-policy ,#'continue)
"/rsbtest/reader/construction")
`("/rsbtest/reader/construction?foo=bar"
()
"/rsbtest/reader/construction")
;; Filters
`("/rsbtest/reader/construction"
(:filters (list (lambda (event) (declare (ignore event)))))
"/rsbtest/reader/construction")
;; No transports => error
'("/rsbtest/reader/construction"
(:transports ((t :enabled nil)))
error))
(addtest (reader-root
:documentation
"Test receiving data sent by an informer in a blocking
mode.")
receive/blocking
(with-participant (informer :informer "/rsbtest/reader/receive/blocking")
(with-participant (reader :reader "/rsbtest/reader/receive/blocking")
(ensure-random-cases 32 ((data a-string))
(send informer data)
(check-event (receive reader :block? t)
"/rsbtest/reader/receive/blocking" data)))))
(addtest (reader-root
:documentation
"Test receiving data sent by an informer in a non-blocking
mode.")
receive/non-blocking
(with-participant (informer :informer "/rsbtest/reader/receive/non-blocking")
(with-participant (reader :reader "/rsbtest/reader/receive/non-blocking")
(ensure-random-cases 32 ((data a-string))
(send informer data)
(let ((received
(loop :for received = (receive reader :block? nil)
:when received :do (return received))))
(check-event received
"/rsbtest/reader/receive/non-blocking" data))))))
(rsb.test::define-error-hook-test-case (reader)
;; Force an error during dispatch by injecting a signaling
;; pseudo-filter.
(push (lambda (event)
(let ((error (make-condition 'simple-error
:format-control "I hate ~A"
:format-arguments (list event))))
(push error expected-errors)
(error error)))
(receiver-filters reader))
;; Try to send and receive an event to trigger the error.
(send informer "foo")
(receive reader :block? nil))
| 3,461 | Common Lisp | .lisp | 91 | 31.395604 | 79 | 0.649746 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 339304fd5c3c1826969844af115dba955489c6fb9070fa07d493dd4e4e9d661c | 25,186 | [
-1
] |
25,187 | package.lisp | open-rsx_rsb-cl/test/patterns/request-reply/package.lisp | ;;;; package.lisp --- Package definition for unit tests of the patterns.request-reply module.
;;;;
;;;; Copyright (C) 2011-2016 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:defpackage #:rsb.patterns.request-reply.test
(:use
#:cl
#:let-plus
#:iterate
#:more-conditions
#:lift
#:rsb
#:rsb.patterns.request-reply
#:rsb.test
#:rsb.patterns.test)
(:import-from #:rsb.patterns.request-reply
#:method1
#:local-method
#:remote-method)
(:export
#:patterns-request-reply-root)
(:documentation
"This package contains unit tests for the patterns.request-reply
module."))
(cl:in-package #:rsb.patterns.request-reply.test)
(deftestsuite patterns-request-reply-root (patterns-root)
()
(:documentation
"Root unit test suite for the patterns.request-reply module."))
| 858 | Common Lisp | .lisp | 30 | 25.3 | 93 | 0.712195 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 70ff26a62b30831febd84058f4a5dc7c1c02e29fc4bb9844d40fb5ad41900c50 | 25,187 | [
-1
] |
25,188 | server.lisp | open-rsx_rsb-cl/test/patterns/request-reply/server.lisp | ;;;; server.lisp --- Unit tests for the method1 and server classes.
;;;;
;;;; Copyright (C) 2011, 2012, 2013, 2014, 2015 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.patterns.request-reply.test)
(deftestsuite method1-root (patterns-request-reply-root)
()
(:documentation
"Test suite for `method1' class."))
(addtest (method1-root
:documentation
"Test constructing `method1' instances.")
construction
(ensure-cases (initargs expected)
'(;; Some invalid instantiations.
(() missing-required-initarg) ; missing :name
((:name "foo") missing-required-initarg) ; missing :server
((:name "illegal/name" :server t) type-error)
((:name "illegal name" :server t) type-error)
((:name "i113g4l n4m3" :server t) type-error)
;; These are valid.
((:name "legal-name" :server t) t))
(let+ (((&flet do-it ()
(apply #'make-instance 'method1
:scope (make-scope "/") initargs))))
(case expected
(missing-required-initarg
(ensure-condition 'missing-required-initarg (do-it)))
(type-error
(ensure-condition 'type-error (do-it)))
(t
(do-it))))))
(deftestsuite server-root (patterns-request-reply-root)
()
(:documentation
"Test suite for the `server' class."))
(addtest (server-root
:documentation
"Test constructing `server' instances.")
construction
(ensure-cases (initargs &optional expected)
`(;; Some invalid constructions.
(() missing-required-initarg) ; scope
((:scope "/" :transform-option ,#'1+) type-error)
((:scope "/" :transform-option ,#'1+) type-error)
;; These are valid.
((:scope "/" :transform-option ((:return . ,#'1+))))
((:scope "/" :transform-option ((:argument . ,#'1+))))
((:scope "/" :transform-option ((:return . ,#'1+) (:argument . ,#'1+))))
((:scope "/" :transform-option ((:argument . ,#'1+) (:return . ,#'1+)))))
(let+ (((&flet do-it ()
(apply #'make-instance 'server initargs))))
(case expected
(missing-required-initarg
(ensure-condition 'missing-required-initarg (do-it)))
(type-error
(ensure-condition 'type-error (do-it)))
(t
(do-it))))))
(addtest (server-root
:documentation
"Test adding methods to a `server' instance.")
set-method
(with-active-participants
((server (make-instance
'server
:scope "/rsbtest/patterns/request-reply/server-root/server"))
(method (make-instance
'method1
:scope (make-scope "/rsbtest/patterns/request-reply/server-root/server/foo")
:name "foo"
:server server)))
(ensure-cases (name method expected)
`(("foo" ,method ,method)
("foo" ,method ,method)
(nil ,method ,method)
("foo" nil nil)
(nil nil nil)
;; invalid method name => type-error
("%invalidname" ,method type-error))
(case expected
(type-error
(ensure-condition 'type-error
(setf (server-method server name) method)))
(t
(let ((result-1 (setf (server-method server name) method))
(result-2 (server-method server name :error? nil)))
(ensure-same result-1 expected)
(ensure-same result-2 expected)))))))
| 3,670 | Common Lisp | .lisp | 90 | 32.277778 | 93 | 0.557395 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 676171d9e03cf9d8d474836f1234501f7b8d3dcf627207c2192640c9d8d2dc7f | 25,188 | [
-1
] |
25,189 | future.lisp | open-rsx_rsb-cl/test/patterns/request-reply/future.lisp | ;;;; future.lisp --- Unit tests for the future class.
;;;;
;;;; Copyright (C) 2011, 2012, 2013, 2014 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.patterns.request-reply.test)
(deftestsuite future-root (patterns-request-reply-root)
()
(:documentation
"Test suite for the future protocol and the `future' class."))
(addtest (future-root
:documentation
"Smoke test for the future class with result retrieval in a
separate thread.")
smoke/threads
(ensure-cases (result-args result
expected-done expected-error
expected-value expected-tag)
'(;; Without timeout and with error signaling
(() (:result :foo) :done nil :foo :done)
(() (:error "bla") :failed t nil nil)
;; Without timeout and without error signaling
((:error? nil) (:result :foo) :done nil :foo :done)
((:error? nil) (:error "bla") :failed nil nil :failed)
;; With timeout and with error signaling
((:timeout .04) (:result :foo) :done nil :foo :done)
((:timeout .04) (:error "bla") :failed t nil nil)
((:timeout .04) (:none) nil t nil nil)
;; With timeout and without error signaling
((:timeout .04 :error? nil) (:result :foo) :done nil :foo :done)
((:timeout .04 :error? nil) (:error "bla") :failed nil nil :failed)
((:timeout .04 :error? nil) (:none) nil nil nil :timeout))
(iter (repeat 10)
(let+ ((future (make-instance 'future))
done error value tag
((&flet make-receiver (args)
(bt:make-thread
(lambda ()
(handler-case
(multiple-value-setq (value tag)
(apply #'future-result future args))
(condition (condition)
(setf error condition)))
(setf done (future-done? future)))))))
(make-receiver result-args)
(sleep (random .01))
(case (first result)
(:result (setf (future-result future) (second result)))
(:error (setf (future-error future) (second result))))
(sleep .08)
(ensure-same done expected-done)
(unless expected-error
(ensure-same value expected-value)
(ensure-same tag expected-tag))
(when expected-error
(ensure (typep error 'condition)))))))
(addtest (future-root
:documentation
"Smoke test for the future class with result retrieval in
the same thread as everything else.")
smoke/no-threads
(ensure-cases (result-args result
expected-done expected-error
expected-value expected-tag)
'(;; Without timeout and with error signaling
(() (:result :foo) :done nil :foo :done)
(() (:error "bla") :failed :error nil nil)
;; Without timeout and without error signaling
((:error? nil) (:result :foo) :done nil :foo :done)
((:error? nil) (:error "bla") :failed nil nil :failed)
;; With timeout and with error signaling
((:timeout .02) (:result :foo) :done nil :foo :done)
((:timeout .02) (:error "bla") :failed :error nil nil)
((:timeout .02) (:none) nil :timeout nil nil)
;; With timeout and without error signaling
((:timeout .02 :error? nil) (:result :foo) :done nil :foo :done)
((:timeout .02 :error? nil) (:error "bla") :failed nil nil :failed)
((:timeout .02 :error? nil) (:none) nil nil nil :timeout))
(iter (repeat 10)
(let ((future (make-instance 'future)))
;; Maybe set a result or error.
(case (first result)
(:result (setf (future-result future) (second result)))
(:error (setf (future-error future) (second result))))
;; Check done state.
(ensure-same (future-done? future) expected-done)
;; Try retrieving the result.
(ecase expected-error
(:error
(ensure-error (apply #'future-result future result-args)))
(:timeout
(ensure-condition 'bt:timeout
(apply #'future-result future result-args)))
((nil)
(ensure-same (apply #'future-result future result-args)
(values expected-value expected-tag))))))))
| 4,913 | Common Lisp | .lisp | 96 | 39.822917 | 84 | 0.516947 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 1ced6f68bc4cd9c052810fac5607d44c736dde5a7287f15addec3f61d5d0ccb4 | 25,189 | [
-1
] |
25,190 | remote-server.lisp | open-rsx_rsb-cl/test/patterns/request-reply/remote-server.lisp | ;;;; remote-server.lisp --- Unit tests for the remote-server class.
;;;;
;;;; Copyright (C) 2011-2016 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.patterns.request-reply.test)
;;; `remote-method' tests
(deftestsuite remote-method-root (patterns-request-reply-root)
()
(:documentation
"Test suite for `remote-method' class."))
(addtest (remote-method-root
:documentation
"Test constructing `remote-method' instances.")
construction
(make-instance 'remote-method
:scope "/remoteserver/foo"
:name "foo"
:server t))
;;; `remote-server' tests
(deftestsuite remote-server-root (patterns-request-reply-root
participant-suite)
()
(:documentation
"Unit tests for the `remote-server' class."))
(define-basic-participant-test-cases (:remote-server
:check-transport-urls? nil)
'("/rsbtest/remoteserver/construction"
()
"/rsbtest/remoteserver/construction")
'("/rsbtest/remoteserver/construction"
(:transports ((:inprocess &inherit)))
"/rsbtest/remoteserver/construction")
'("/rsbtest/remoteserver/construction"
(:transports ((t &inherit) (:inprocess &inherit)))
"/rsbtest/remoteserver/construction")
`("/rsbtest/remoteserver/construction"
(:parent ,*simple-parent*)
"/rsbtest/remoteserver/construction")
'("/rsbtest/remoteserver/construction"
(:introspection? nil)
"/rsbtest/remoteserver/construction")
'("/rsbtest/remoteserver/construction"
(:introspection? t)
"/rsbtest/remoteserver/construction")
'("inprocess://localhost/rsbtest/remoteserver/construction"
()
"/rsbtest/remoteserver/construction")
'("/rsbtest/remoteserver/construction?foo=bar"
()
"/rsbtest/remoteserver/construction")
;; No transports => error
'("/" (:transports ((t :enabled nil))) error))
(addtest (remote-server-root
:documentation
"Test adding methods to a `remote-server' instance.")
set-method
(with-participant (server :remote-server "/rsbtest/remoteserver/set-method")
(ensure-cases (name expected)
`(("foo" t)
(nil t)
;; invalid method name => error
("%invalidname" type-error))
(let+ (((&flet do-it ()
(server-method server name))))
(case expected
(type-error (ensure-condition 'type-error (do-it)))
((t) (ensure (do-it))))))))
| 2,564 | Common Lisp | .lisp | 68 | 31.102941 | 78 | 0.642973 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 2823474dd1f31b58aa64a24bdbcbf79b68376358ea1fe889fd1071471dd52ed8 | 25,190 | [
-1
] |
25,191 | integration.lisp | open-rsx_rsb-cl/test/patterns/request-reply/integration.lisp | ;;;; integration.lisp --- Integration test for local and remote servers.
;;;;
;;;; Copyright (C) 2011, 2012, 2013, 2014, 2015 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.patterns.request-reply.test)
(deftestsuite integration-root (patterns-request-reply-root)
((url "inprocess:/rsbtest/server/integration"))
(:documentation
"Integration test for `local-server' and `remote-server'
classes."))
(addtest (integration-root
:documentation
"Smoke test for communication between `local-server' and
`remote-server' instances.")
smoke
(with-participant (local-server :local-server url)
(with-methods (local-server)
(("echo" (arg string)
arg)
("nop" ()
(values)))
(with-participant (remote-server :remote-server url)
(ensure-random-cases 100 ((s a-string))
;; Invoke with payload result using `call' method
(ensure-same (call remote-server "echo" s) s
:test #'string=)
;; Invoke with event result using `call' method
(call remote-server "echo" s :return :event)
;; Invoke using `funcall'
(ensure-same (funcall (server-method remote-server "echo") s) s
:test #'string=)
;; Invoke with event result using `funcall'
(funcall (server-method remote-server "echo") s
:return :event))
;; Invoke without argument using `funcall'
(funcall (server-method remote-server "nop"))))))
(addtest (integration-root
:documentation
"Test communication in which the `local-method' and the
`remote-method' operate on events.")
smoke/event
(with-participant (local-server :local-server url)
(with-methods (local-server)
(("echo" (arg :event) arg))
(with-participant (remote-server :remote-server url)
(let ((event (make-event
(merge-scopes
'("echo") (participant-scope remote-server))
5)))
;; Invoke with payload result using `call' method
(ensure-same (call remote-server "echo" event) 5 :test #'=)
;; Invoke with event result using `call' method
(ensure (typep (call remote-server "echo"
event :return :event)
'event))
;; Invoke using `funcall'
(ensure-same (funcall (server-method remote-server "echo") event)
5 :test #'=)
;; Invoke with event result using `funcall'
(ensure (typep (funcall (server-method remote-server "echo")
event :return :event)
'event)))))))
(addtest (integration-root
:documentation
"Test catch-all method on `local-server' side.")
local-catch-all-method
(with-participant (local-server :local-server url)
(with-methods (local-server)
((nil (arg integer) (1+ arg)))
(with-participant (remote-server :remote-server url)
(ensure-same (call remote-server "foo" 1) 2)
(ensure-same (call remote-server "bar" 3) 4)))))
(addtest (integration-root
:documentation
"Test catch-all method on `remote-server' side.")
remote-catch-all-method
(with-participant (local-server :local-server url)
(with-methods (local-server)
(("foo" (arg integer) (1+ arg)))
(with-participant (remote-server :remote-server url)
(let ((scope (merge-scopes '("foo") (uri->scope-and-options
(puri:uri url)))))
(ensure-same (call remote-server nil (make-event scope 1)) 2))))))
(addtest (integration-root
:documentation
"Test calling a remote method which signals an error during
execution.")
error
(with-participant (local-server :local-server url)
(with-methods (local-server)
(("error" (arg string)
(error "intentional error")))
(with-participant (remote-server :remote-server url)
;; Invoke using `call' method
(ensure-condition 'remote-method-execution-error
(call remote-server "error" "foo"))
;; Invoke asynchronously using `call' method
(ensure-same (future-result
(call remote-server "error" "foo"
:block? nil)
:error? nil)
(values nil :failed))
;; Invoke using `funcall'
(ensure-condition 'remote-method-execution-error
(funcall (server-method remote-server "error") "foo"))
;; Invoke asynchronously using `funcall'
(ensure-same (future-result
(funcall (server-method remote-server "error")
"foo"
:block? nil)
:error? nil)
(values nil :failed))))))
(addtest (integration-root
:documentation
"Test timeout behavior when calling non-existent methods.")
timeout
(with-participant (remote-server :remote-server url)
;; Invoke using `call' method
(ensure-condition 'bt:timeout
(call remote-server "nosuchmethod" "does-not-matter"
:timeout .1))
(ensure-condition 'bt:timeout
(future-result (call remote-server "nosuchmethod" "does-not-matter"
:block? nil)
:timeout .1))
;; Invoke using `funcall'
(ensure-condition 'bt:timeout
(funcall (server-method remote-server "nosuchmethod") "does-not-matter"
:timeout .1))
(ensure-condition 'bt:timeout
(future-result (funcall (server-method remote-server "nosuchmethod")
"does-not-matter"
:block? nil)
:timeout .1))))
(addtest (integration-root
:documentation
"Test transforming events between `local-server' and
`remote-server' instances.")
transform
(let+ (((&flet event-1+ (event)
(incf (event-data event))
event))
((&flet event-2* (event)
(setf (event-data event) (* 2 (event-data event)))
event)))
(with-participant (local-server :local-server url
:transform `((:argument . ,#'event-1+)
(:return . ,#'event-2*)))
(with-methods (local-server)
(("addfive" (arg integer)
(+ arg 5)))
(with-participant (remote-server :remote-server url
:transform `((:argument . ,#'event-2*)
(:return . ,#'event-1+)))
(ensure-random-cases 100 ((i an-integer))
;; Invoke with payload result using `call' method
(ensure-same (call remote-server "addfive" i)
(1+ (* 2 (+ 5 (1+ (* 2 i)))))
:test #'=)))))))
| 7,109 | Common Lisp | .lisp | 160 | 32.4375 | 81 | 0.560341 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 04f24f9cb3d545c08dc39dbe86b0ee87b8375e690a04108495b39ff34e6449cf | 25,191 | [
-1
] |
25,192 | local-server.lisp | open-rsx_rsb-cl/test/patterns/request-reply/local-server.lisp | ;;;; local-server.lisp --- Unit tests for the local-server class.
;;;;
;;;; Copyright (C) 2011-2016 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.patterns.request-reply.test)
;;; `local-method' tests
(deftestsuite local-method-root (patterns-request-reply-root)
()
(:documentation
"Test suite for `local-method' class."))
(addtest (local-method-root
:documentation
"Test constructing `local-method' instances.")
construction
;; Missing :callback initarg
(ensure-condition 'missing-required-initarg
(make-instance 'local-method :scope (make-scope "/foo") :name "foo")))
;;; `local-server' tests
(deftestsuite local-server-root (patterns-request-reply-root
participant-suite)
()
(:documentation
"Test suite for the `local-server' class."))
(define-basic-participant-test-cases (:local-server
:check-transport-urls? nil)
'("/rsbtest/localserver/construction"
()
"/rsbtest/localserver/construction")
'("/rsbtest/localserver/construction"
(:transports ((:inprocess &inherit)))
"/rsbtest/localserver/construction")
'("/rsbtest/localserver/construction"
(:transports ((t &inherit) (:inprocess &inherit)))
"/rsbtest/localserver/construction")
`("/rsbtest/localserver/construction"
(:parent ,*simple-parent*)
"/rsbtest/localserver/construction")
'("/rsbtest/localserver/construction"
(:introspection? nil)
"/rsbtest/localserver/construction")
'("/rsbtest/localserver/construction"
(:introspection? t)
"/rsbtest/localserver/construction")
'("inprocess://localhost/rsbtest/localserver/construction"
()
"/rsbtest/localserver/construction")
'("/rsbtest/localserver/construction?foo=bar"
()
"/rsbtest/localserver/construction")
;; No transports => error
'("/" (:transports ((t :enabled nil))) error))
(addtest (local-server-root
:documentation
"Test adding methods to a `local-server' instance.")
set-method
(with-participant (server :local-server "/rsbtest/localserver/set-method")
(ensure-cases (name method args expected)
`(("foo" ,(lambda ()) () t)
("foo" ,(lambda ()) () t)
("foo" nil () nil)
(nil ,(lambda ()) () t)
(nil nil () nil)
("bar" ,(lambda ()) (:argument :event) t)
("bar" ,(lambda ()) (:argument :payload) t)
;; invalid method name => type-error
("%invalidname" ,(lambda ()) () type-error)
;; invalid argument style => type-error
("bar" ,(lambda ()) (:argument :foo) type-error))
(let+ (((&flet do-it ()
(values
(setf (apply #'server-method server name args) method)
(server-method server name :error? nil)))))
(case expected
(type-error (ensure-condition 'type-error (do-it)))
((t) (ensure (notany #'null (multiple-value-list (do-it)))))
(t (ensure-same (do-it) (values expected expected))))))))
(addtest (local-server-root
:documentation
"Test methods on `call' for the `local-server' class.")
call
(with-participant (server :local-server "/rsbtest/localserver/call")
(let ((argument))
(setf (server-method server "echopayload")
(lambda (x) (setf argument x))
(server-method server "echoevent" :argument :event)
(lambda (x) (setf argument x) (event-data x))
(server-method server "error")
(lambda (x) (declare (ignore x)) (error "intentional error")))
(ensure-cases (method arg expected-argument expected-result)
'(("echopayload" "foo" "foo" "foo")
("echoevent" "foo" event "foo")
("error" "foo" :none string))
(setf argument :none)
(let* ((scope (merge-scopes
(list method) "/rsbtest/localserver/call"))
(event (let ((event (make-event scope arg)))
(setf (event-sequence-number event)
0
(event-origin event)
(uuid:make-v4-uuid))
event))
(result (call server (server-method server method) event))
(result-data (event-data result)))
(if (typep expected-argument '(and symbol (not keyword)))
(ensure (typep argument expected-argument))
(ensure-same argument expected-argument
:test #'equal))
(ensure (typep result 'event))
(if (symbolp expected-result)
(ensure (typep result-data expected-result))
(ensure-same result-data expected-result
:test #'equal)))))))
| 5,157 | Common Lisp | .lisp | 113 | 35.893805 | 78 | 0.559498 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 2b04ddbf30b3febf44f65529ad8250bb9cafabb068fa9d2417d94479dac3f5af | 25,192 | [
-1
] |
25,193 | macros.lisp | open-rsx_rsb-cl/test/patterns/request-reply/macros.lisp | ;;;; macros.lisp --- Unit tests for macros of the patterns module.
;;;;
;;;; Copyright (C) 2011, 2012, 2013, 2014, 2015 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.patterns.request-reply.test)
(deftestsuite macros-root (patterns-request-reply-root)
()
(:documentation
"Root test suite for tests of macros in the patterns module."))
;;; Local server-related macros
(addtest (macros-root
:documentation
"Smoke test for the `with-methods' macro.")
with-methods/smoke
(with-participant (server :local-server "inprocess:/rsbtest/patterns/request-reply/macros-root/with-methods/smoke")
(with-methods (server)
;; Normal method names
(("mymethod" (foo string) foo)
(:myothermethod (bar integer)
(declare (ignore bar)))
("noarg" ())
("eventarg" (baz :event)
(declare (ignore baz)))
("notype" (fez)
(declare (ignore fez)))
;; Catch-all methods
(nil (foo string) foo)
(nil (bar integer)
(declare (ignore bar)))
(nil ())
(nil (baz :event)
(declare (ignore baz)))
(nil (fez)
(declare (ignore fez))))
(ensure (server-method server "mymethod"))
(ensure (server-method server "MYOTHERMETHOD"))
(ensure (server-method server "noarg"))
(ensure (server-method server "eventarg"))
(ensure (server-method server "notype"))
(ensure (server-method server nil)))
(ensure-null (server-methods server))))
(addtest (macros-root
:documentation
"Test macroexpansion behavior of `with-methods' macro.")
with-methods/macroexpand
(ensure-cases (method expected)
'(;; Some invalid constructions.
(("invalid name" (foo string) foo) type-error)
(("%invalidname" (foo string) foo) type-error)
(("invalidtype" (foo 5) foo) type-error)
;; These are valid.
(("validname" (foo string) foo) t)
((:validname (foo string) foo) t)
((validname (foo string) foo) t)
(("valid-name" (foo string) foo) t)
(("v41id_n4m3" (foo string) foo) t)
(("eventarg" (foo :event) foo) t)
(("noarg" () :const) t)
;; Catch-all methods.
((nil (foo string) foo) t)
((nil (foo :event) foo) t)
((nil () :const) t))
(case expected
(type-error (ensure-condition 'type-error
(macroexpand `(with-methods (server) (,method)))))
(t (macroexpand `(with-methods (server) (,method)))))))
(addtest (macros-root
:documentation
"Test handling of error-policy keyword parameter in
`with-participant' macro when used with a :local-server
participant.")
with-participant/local-server/error-policy
(let ((calls '()))
(macrolet
((test-case (&optional policy)
`(with-participant (local-server :local-server
"inprocess:/rsbtest/patterns/request-reply/macros-root/with-local-server/error-policy"
:transform `((:argument . ,#'mock-transform/error))
,@(when policy `(:error-policy ,policy)))
(with-methods (local-server) (("echo" (arg) arg))
(with-participant (remote-server :remote-server
"inprocess:/rsbtest/patterns/request-reply/macros-root/with-local-server/error-policy")
(call remote-server "echo" 1))))))
;; Without an error policy, the transform error should just be
;; signaled.
(ensure-condition remote-call-error
(test-case))
;; With `continue' error policy, calling the method should
;; proceed without the failing transformation.
#+TODO-enable-when-fixed
(let ((result (test-case (lambda (condition)
(push condition calls)
(continue condition)))))
(ensure-same result 1)
(ensure-same (length calls) 1)
(ensure (typep (first calls) 'rsb.event-processing:transform-error))))))
;;; Remote server-related macros
(addtest (macros-root
:documentation
"Test handling of error-policy keyword parameter in
`with-participant' macro when used with a :remote-server
participant.")
with-participant/remote-server/error-policy
(let ((calls '()))
(macrolet
((test-case (&optional policy)
`(with-participant (remote-server :remote-server
"inprocess:/rsbtest/patterns/request-reply/macros-root/with-remote-server/error-policy"
:transform `((:return . ,#'mock-transform/error))
,@(when policy `(:error-policy ,policy)))
(with-participant (local-server :local-server
"inprocess:/rsbtest/patterns/request-reply/macros-root/with-remote-server/error-policy")
(with-methods (local-server) (("echo" (arg) arg))
(call remote-server "echo" 1))))))
;; Without an error policy, the transform error should just be
;; signaled.
(ensure-condition remote-call-error
(test-case))
;; With `continue' error policy, calling the method should
;; proceed without the failing transformation.
#+TODO-enable-when-fixed
(let ((result (test-case (lambda (condition)
(push condition calls)
(continue condition)))))
(ensure-same result 1)
(ensure-same (length calls) 1)
(ensure (typep (first calls) 'rsb.event-processing:transform-error))))))
| 6,006 | Common Lisp | .lisp | 128 | 35.632813 | 136 | 0.568648 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 88ba54b2b4b7efaec7d1233a8d311f30c6d39b6b0249bb39c137e1dbc65eb1db | 25,193 | [
-1
] |
25,194 | model.lisp | open-rsx_rsb-cl/test/introspection/model.lisp | ;;;; model.lisp --- Tests for model classes.
;;;;
;;;; Copyright (C) 2014, 2015 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.introspection.test)
(deftestsuite introspection-model-root (introspection-root)
()
(:documentation
"Unit test suite for the model classes."))
;;; Functions related to `process-info' classes
(addtest (introspection-model-root
:documentation
"Smoke test for the `current-process-info' function.")
current-process-info/smoke
(let ((info (current-process-info)))
(ensure (typep (process-info-process-id info) 'non-negative-integer))
(ensure (typep (process-info-program-name info) 'string))
(ensure (typep (process-info-commandline-arguments info) 'list))
(ensure (typep (process-info-start-time info) 'local-time:timestamp))
(ensure (typep (process-info-executing-user info) 'string))
(ensure (typep (process-info-rsb-version info) '(or null string)))
(ensure (typep (process-info-display-name info) '(or null string)))))
;;; Functions related to `host-info' classes
(addtest (introspection-model-root
:documentation
"Smoke test for the `current-host-info' function.")
current-host-info/smoke
(let ((info (current-host-info)))
(ensure (typep (host-info-id info) 'string))
(ensure (typep (host-info-hostname info) 'string))
(ensure (typep (host-info-machine-type info) 'string))
(ensure (typep (host-info-machine-version info) 'string))
(ensure (typep (host-info-software-type info) 'string))
(ensure (typep (host-info-software-version info) 'string))))
;;; `hello' and `bye' classes
(rsb.model.test::define-simple-model-class-tests (hello :suite-prefix #:introspection-model-)
;; These are OK.
`((:participant ,(make-instance 'participant-info
:kind :listener
:id (uuid:make-v1-uuid)
:scope (make-scope "/Bla")
:type "bla"
:transports '())
:process ,(current-process-info)
:host ,(current-host-info))))
(rsb.model.test::define-simple-model-class-tests (bye :suite-prefix #:introspection-model-)
;; Missing required initargs.
'(() missing-required-initarg)
;; These are OK.
`((:id ,(uuid:make-v1-uuid))))
| 2,539 | Common Lisp | .lisp | 51 | 42.705882 | 93 | 0.612031 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 3cb67b28836e2f8bcb1e052f2e618c7bcbbaa525387f63e77902f386b3b799f2 | 25,194 | [
-1
] |
25,195 | package.lisp | open-rsx_rsb-cl/test/introspection/package.lisp | ;;;; package.lisp --- Package definition for unit tests of the introspection module.
;;;;
;;;; Copyright (C) 2014, 2015 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:defpackage #:rsb.introspection.test
(:use
#:cl
#:alexandria
#:let-plus
#:iterate
#:more-conditions
#:lift
#:rsb
#:rsb.patterns.request-reply
#:rsb.introspection
#:rsb.test)
;; Platform information functions
(:import-from #:rsb.introspection
#:current-process-id
#:current-program-name-and-commandline-arguments
#:current-process-start-time
#:current-host-id
#:remote-introspection-database)
;; Root test suite
(:export
#:introspection-root)
(:documentation
"This package contains unit tests for the introspection module."))
(cl:in-package #:rsb.introspection.test)
;;; Utilities
(defparameter +introspection-configuration+
'(((:introspection :enabled) . t)
((:transport :socket :enabled) . nil)
((:transport :inprocess :enabled) . t)))
(defun make-introspection-scope (&optional (suffix '()))
(merge-scopes suffix +introspection-scope+))
(defun make-introspection-participants-scope (&optional (suffix '()))
(merge-scopes suffix +introspection-participants-scope+))
(defun send-introspection-event (datum &rest args &key
suffix-scope
&allow-other-keys)
(let ((scope (make-introspection-participants-scope suffix-scope)))
(with-participant (informer :informer scope :introspection? nil)
(apply #'send informer datum (remove-from-plist args :suffix-scope)))))
(defmacro with-condition-tracking ((handler-name check-conditions-name
&optional
(clear-calls-name (gensym)))
&body body)
(with-unique-names (calls)
`(let+ ((,calls '())
((&labels ,handler-name (condition)
(appendf ,calls (list condition))
(continue condition)))
((&labels ,check-conditions-name (expected)
(let ((num-calls (length ,calls))
(num-expected (length expected)))
(ensure-same num-calls num-expected :test #'=
:report "~@<~D call~:P but expected ~D~:@>"
:arguments (num-calls num-expected)))
(mapc (lambda+ (call (expected-type &rest expected-substrings))
(ensure (typep call expected-type))
(let* ((*print-right-margin* most-positive-fixnum)
(*print-length* most-positive-fixnum)
(text (princ-to-string call)))
(dolist (expected-substring expected-substrings)
(ensure-same expected-substring text
:test #'search))))
,calls expected)
(,clear-calls-name)))
((&labels ,clear-calls-name ()
(setf ,calls '()))))
,@body)))
;;; Test suite
(deftestsuite introspection-root (root)
()
(:dynamic-variables
(rsb:*configuration* +introspection-configuration+))
(:documentation
"Root unit test suite of the introspection module."))
| 3,359 | Common Lisp | .lisp | 80 | 31.675 | 84 | 0.585097 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | d6f062945d61750ad34ad205ce018a54bced2b20e181eb0777c772b989c3fbdd | 25,195 | [
-1
] |
25,196 | reloading.lisp | open-rsx_rsb-cl/test/introspection/reloading.lisp | ;;;; reloading.lisp --- Unit tests for introspection database reloading.
;;;;
;;;; Copyright (C) 2014, 2015 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.introspection.test)
(deftestsuite reloading-root (introspection-root)
()
(:documentation
"Unit test suite for the reloading the introspection database."))
(addtest (reloading-root
:documentation
"Smoke test for reinitializing the introspection database.")
smoke
;; The listener forces a `local-introspection' database. Otherwise
;; `reinitialize-introspection' would be a noop.
(with-participant (listener :listener "inprocess:/rsbtest/introspection/reloading")
(let+ (((&flet introspection-data ()
(rsb.introspection::with-local-database (database)
(values (rsb.introspection::introspection-host database)
(rsb.introspection::introspection-process database)))))
((&values old-host old-process) (introspection-data))
((&values new-host new-process) (progn
(reinitialize-introspection)
(introspection-data))))
(ensure-different old-host new-host :test #'eq)
(ensure-different old-process new-process :test #'eq))))
| 1,350 | Common Lisp | .lisp | 27 | 40.814815 | 85 | 0.649735 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 41c26f0b3aafc3d221dc1e323f707c484072ee940ca372925dd0ce005b24f839 | 25,196 | [
-1
] |
25,197 | local-introspection.lisp | open-rsx_rsb-cl/test/introspection/local-introspection.lisp | ;;;; local-introspection.lisp --- Unit tests for the local-introspection class.
;;;;
;;;; Copyright (C) 2014, 2015, 2016 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.introspection.test)
(deftestsuite local-introspection-root (introspection-root)
()
(:documentation
"Unit test suite for the `local-introspection' class."))
(rsb.test:define-basic-participant-test-cases (rsb.introspection::local-introspection)
'("/rsbtest/local-introspection/construction"
()
"/rsbtest/local-introspection/construction")
'("/rsbtest/local-introspection/construction"
(:transports ((:inprocess &inherit)))
"/rsbtest/local-introspection/construction")
'("/rsbtest/local-introspection/construction"
(:transports ((t &inherit) (:inprocess &inherit)))
"/rsbtest/local-introspection/construction")
'("/rsbtest/local-introspection/construction"
(:converters ((t . :foo)))
"/rsbtest/local-introspection/construction")
'("inprocess:/rsbtest/local-introspection/construction"
()
"/rsbtest/local-introspection/construction")
`("inprocess:/rsbtest/local-introspection/construction"
(:error-policy ,#'continue)
"/rsbtest/local-introspection/construction")
`("/rsbtest/local-introspection/construction?foo=bar"
()
"/rsbtest/local-introspection/construction")
;; No transports => error
'("/rsbtest/local-introspection/construction"
(:transports ((t :enabled nil)))
error))
(defun listener-creation-error-caused-by-local-introspection-creation-error? (condition)
(flet ((type-and-kind? (condition type kind)
(and (typep condition type)
(eq (participant-creation-error-kind condition) kind))))
(and (type-and-kind? condition 'participant-creation-error :listener)
(type-and-kind? (cause condition) 'participant-creation-error :local-introspection))))
(deftype listener-creation-error-caused-by-local-introspection-creation-error ()
'(satisfies listener-creation-error-caused-by-local-introspection-creation-error?))
(addtest (local-introspection-root
:documentation
"Test conditions signaled when creating a participant fails
because of local-introspection errors.")
contruction/chained-participant-creation-error
;; Bind `*local-database*' to nil to ensure an attempt is made to
;; create the database.
(let+ ((rsb.introspection::*local-database* nil)
((&flet do-it ()
(ensure-condition 'listener-creation-error-caused-by-local-introspection-creation-error
(make-participant :listener "/" :transports '((:inprocess :enabled t)
(t :enabled nil)))))))
;; `local-introspection' creation fails because configuration does
;; not select a transport.
(let ((*configuration* '(((:transport :socket :enabled) . nil)
((:introspection :enabled) . t))))
(do-it))
;; `local-introspection' creation fails because configuration
;; specifies a non-existent transport.
(let ((*configuration* '(((:transport :socket :enabled) . nil)
((:transport :no-such-transport :enabled) . t)
((:introspection :enabled) . t))))
(do-it))))
(addtest (local-introspection-root
:documentation
"Smoke test for the `local-introspection' class.")
smoke
(with-participant (introspection :local-introspection +introspection-scope+)
;; Survey existing participants.
(send-introspection-event rsb.converter:+no-value+
:scope-suffix "/participants"
:method :|survey|)
;; Call "echo" method of introspection server.
(let ((server-scope (participant-scope
(rsb.patterns:participant-child
introspection :server :local-server))))
(with-participant (server :remote-server server-scope)
(call server "echo" rsb.converter:+no-value+)))))
(addtest (local-introspection-root
:documentation
"Test application of the configured error policy in
`local-introspection' instances.")
error-policy
(with-condition-tracking (record-and-continue check-conditions)
(with-participant (introspection :local-introspection +introspection-scope+
:error-policy #'record-and-continue)
;; All of the following are ignored because of the survey
;; filter.
(send-introspection-event :foo)
(send-introspection-event "ping")
(send-introspection-event rsb.converter:+no-value+)
(check-conditions '())
;; Invalid request events.
(send-introspection-event "ping" :method :|request|)
(send-introspection-event rsb.converter:+no-value+ :method :|request|)
(check-conditions
'((introspection-protocol-error
"not conform to the REQUEST role within the INTROSPECTION protocol")
(introspection-protocol-error
"not conform to the REQUEST role within the INTROSPECTION protocol")))
(send-introspection-event "ping" :method :|request| :suffix-scope "/foo")
(send-introspection-event
rsb.converter:+no-value+ :method :|request| :suffix-scope "/foo")
(check-conditions
'((introspection-protocol-error
"not conform to the REQUEST role within the INTROSPECTION protocol")
(introspection-protocol-error
"not conform to the REQUEST role within the INTROSPECTION protocol")))
;; Invalid survey events.
(send-introspection-event
"ping"
:method :|survey|
:suffix-scope (format nil "/~A" (uuid:make-null-uuid)))
(send-introspection-event
rsb.converter:+no-value+
:method :|survey|
:suffix-scope (format nil "/~A" (uuid:make-null-uuid)))
(check-conditions
'((introspection-protocol-error
"not conform to the REQUEST role within the INTROSPECTION protocol")
(introspection-protocol-error
"not conform to the REQUEST role within the INTROSPECTION protocol")))
(send-introspection-event "ping" :method :|survey| :suffix-scope "/foo")
(send-introspection-event
rsb.converter:+no-value+ :method :|survey| :suffix-scope "/foo")
(check-conditions
'((introspection-protocol-error
"not conform to the REQUEST role within the INTROSPECTION protocol")
(introspection-protocol-error
"not conform to the REQUEST role within the INTROSPECTION protocol"))))))
(addtest (local-introspection-root
:documentation
"Stress test which surveys a `local-introspection' from
multiple threads in parallel while creating and destroying
participants in a second set of threads.")
stress
(with-participant (introspection :local-introspection +introspection-scope+)
(let+ ((configuration *configuration*)
((&flet participant-noise ()
(let ((*local-database* introspection))
(iter (repeat 30)
(with-participant (server :local-server (string (gensym "/")))
(with-methods (server)
(("echo" (x) x) ("echo2" (x) x) ("echo3" (x) x))))))))
((&flet survey-noise ()
(with-participant (i :informer (introspection-participants-scope))
(iter (repeat 30)
(send i rsb.converter:+no-value+
:method :|survey|)))))
((&flet make-thread-thunk (i)
(lambda ()
(let ((*configuration* configuration))
(if (oddp i)
(participant-noise)
(survey-noise))))))
(threads (mapcar (compose #'bt:make-thread #'make-thread-thunk)
(iota 10))))
(mapc #'bt:join-thread threads))))
| 8,079 | Common Lisp | .lisp | 162 | 40.364198 | 99 | 0.639128 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 21af8d3d09707d9884294ed43382edb7c4bac048db93f53bda33aa7b9da525da | 25,197 | [
-1
] |
25,198 | builder.lisp | open-rsx_rsb-cl/test/introspection/builder.lisp | ;;;; builder.lisp --- Tests for introspection model (un)builder.
;;;;
;;;; Copyright (C) 2015, 2016 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:defpackage #:rsb.introspection.builder.test
(:use
#:cl
#:let-plus
#:lift
#:rsb
#:rsb.introspection)
(:local-nicknames
(#:bp #:architecture.builder-protocol))
(:import-from #:architecture.builder-protocol.test
#:record-un-build-calls/peeking)
(:import-from #:rsb.introspection
#:timing-tracker-%clock-offset
#:timing-tracker-%latency
#:entry-%tracker
#:remote-introspection-database)
(:export
#:rsb-introspection-builder-root)
(:documentation
"This package contains test for the introspection.builder module."))
(cl:in-package #:rsb.introspection.builder.test)
(deftestsuite rsb-introspection-builder-root ()
()
(:documentation
"Unit test suite for the introspection model (un)builder
support."))
(defvar *stop-type* '(or number string uuid:uuid puri:uri scope))
(defun check-un-build-calls (builder atom-type cases)
(mapc (lambda+ ((object expected-calls))
(let+ (((&values &ign calls)
(record-un-build-calls/peeking
#'bp:walk-nodes builder atom-type object)))
(ensure-same calls expected-calls :test #'equal)))
cases))
(addtest (rsb-introspection-builder-root)
remote-introspection-database/smoke
(check-un-build-calls
t nil
`(,(let ((database (make-instance 'remote-introspection-database)))
`(,database ((:peek nil () ,database)
(:visit nil () ,database :database ((:children . *)) ())))))))
(addtest (rsb-introspection-builder-root)
process-entry/smoke
(check-un-build-calls
t *stop-type*
`(,(let* ((start-time (local-time:now))
(commandline-arguments '("a" "b"))
(initargs `(:process-id 0
:program-name "foo"
:start-time ,start-time
:executing-user "user"
:rsb-version "1.2.3"
:display-name "Foo"))
(info (apply #'make-instance 'rsb.model:process-info
:commandline-arguments commandline-arguments
initargs))
(entry (make-instance 'process-entry
:info info
:receiver nil))
(tracker (entry-%tracker entry))
(latency (timing-tracker-%latency tracker)))
`(,entry ((:peek nil () ,entry)
(:visit nil () ,entry :process ((:latency . 1)
(:children . *)
(:commandline-arguments . *))
,initargs)
(:peek :latency () ,latency)
(:visit :latency () ,latency :tracked-quantity ((:history . *))
(:name "latency" :value nil))
,@(mapcar (lambda (x) `(:peek :commandline-arguments () ,x))
commandline-arguments)))))))
(addtest (rsb-introspection-builder-root)
host-entry/smoke
(check-un-build-calls
t *stop-type*
`(,(let* ((initargs '(:id "1"
:hostname "foo"
:machine-type "mt"
:machine-version "mv"
:software-type "st"
:software-version "sv"))
(info (apply #'make-instance 'rsb.model:host-info
initargs))
(entry (make-instance 'host-entry :info info))
(tracker (entry-%tracker entry))
(clock-offset (timing-tracker-%clock-offset tracker))
(latency (timing-tracker-%latency tracker)))
`(,entry ((:peek nil () ,entry)
(:visit nil () ,entry :host ((:clock-offset . 1)
(:latency . 1)
(:children . *))
,initargs)
(:peek :clock-offset () ,clock-offset)
(:visit :clock-offset () ,clock-offset :tracked-quantity ((:history . *))
(:name "clock-offset" :value nil))
(:peek :latency () ,latency)
(:visit :latency () ,latency :tracked-quantity ((:history . *))
(:name "latency" :value nil))))))))
| 4,971 | Common Lisp | .lisp | 103 | 32.990291 | 91 | 0.473597 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 28951fe1d5314fb7bf84ef839c3652fcd240d386fe15c5e6ec5c3c387a5ceb50 | 25,198 | [
-1
] |
25,199 | remote-introspection.lisp | open-rsx_rsb-cl/test/introspection/remote-introspection.lisp | ;;;; remote-introspection.lisp --- Unit tests for the remote-introspection class.
;;;;
;;;; Copyright (C) 2014, 2015, 2016, 2017 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.introspection.test)
;;; Class `introspection-receiver'
(deftestsuite introspection-receiver-root (introspection-root)
()
(:documentation
"Unit test suite for the `introspection-receiver' class."))
(define-basic-participant-test-cases (rsb.introspection::introspection-receiver
:check-transport-urls? nil)
'("/rsbtest/introspection-receiver/construction"
()
"/rsbtest/introspection-receiver/construction")
'("/rsbtest/introspection-receiver/construction"
(:transports ((:inprocess &inherit)))
"/rsbtest/introspection-receiver/construction")
'("/rsbtest/introspection-receiver/construction"
(:transports ((t &inherit) (:inprocess &inherit)))
"/rsbtest/introspection-receiver/construction")
'("/rsbtest/introspection-receiver/construction"
(:converters ((t . :foo)))
"/rsbtest/introspection-receiver/construction")
'("inprocess:/rsbtest/introspection-receiver/construction"
()
"/rsbtest/introspection-receiver/construction")
`("inprocess:/rsbtest/introspection-receiver/construction"
(:error-policy ,#'continue)
"/rsbtest/introspection-receiver/construction")
`("/rsbtest/introspection-receiver/construction?foo=bar"
()
"/rsbtest/introspection-receiver/construction")
;; No transports => error
'("/rsbtest/introspection-receiver/construction"
(:transports ((t :enabled nil)))
error))
;;; Class `remote-introspection-database'
(deftestsuite remote-introspection-database-root (introspection-root)
()
(:documentation
"Unit test suite for the `remote-introspection-database' class."))
(addtest (remote-introspection-database-root
:documentation
"Test printing `remote-introspection-database' instances.")
print
(let ((introspection (make-instance 'remote-introspection-database)))
(ensure (not (emptyp (princ-to-string introspection))))))
;;; Class `remote-introspection'
(deftestsuite remote-introspection-root (introspection-root)
()
(:documentation
"Unit test suite for the `remote-introspection' class."))
(define-basic-participant-test-cases (rsb.introspection::remote-introspection)
'("/rsbtest/remote-introspection/construction"
()
"/rsbtest/remote-introspection/construction")
'("/rsbtest/remote-introspection/construction"
(:transports ((:inprocess &inherit)))
"/rsbtest/remote-introspection/construction")
'("/rsbtest/remote-introspection/construction"
(:transports ((t &inherit) (:inprocess &inherit)))
"/rsbtest/remote-introspection/construction")
'("/rsbtest/remote-introspection/construction"
(:converters ((t . :foo)))
"/rsbtest/remote-introspection/construction")
'("/rsbtest/remote-introspection/construction"
(:receiver-uris ("inprocess:"))
"/rsbtest/remote-introspection/construction")
'("/rsbtest/remote-introspection/construction"
(:response-timeout 2.0)
"/rsbtest/remote-introspection/construction")
'("inprocess:/rsbtest/remote-introspection/construction"
()
"/rsbtest/remote-introspection/construction")
`("inprocess:/rsbtest/remote-introspection/construction"
(:error-policy ,#'continue)
"/rsbtest/remote-introspection/construction")
`("/rsbtest/remote-introspection/construction?foo=bar"
()
"/rsbtest/remote-introspection/construction")
;; No transports => error
'("/rsbtest/remote-introspection/construction"
(:transports ((t :enabled nil)))
error))
(addtest (remote-introspection-root
:documentation
"Smoke test for timer-based updating of
`remote-introspection'.")
update/smoke
(with-participant (introspection :remote-introspection +introspection-scope+
:update-interval .2)
(sleep 1.0)))
(addtest (remote-introspection-root
:documentation
"Test application of the configured error policy in
`remote-introspection' instances.")
error-policy
(with-condition-tracking (record-and-continue check-conditions)
(with-participant (introspection :remote-introspection +introspection-scope+
:error-policy #'record-and-continue)
;; "pong" replies should be ignored.
(send-introspection-event
"pong" :suffix-scope (format nil "/~A" (uuid:make-null-uuid)))
(check-conditions '())
;; Invalid scopes
(send-introspection-event "pong")
(check-conditions
'((introspection-protocol-error
"not conform to the RESPONSE role within the INTROSPECTION protocol"
"Malformed participant scope"
"No participant-id scope component in scope")))
(send-introspection-event "this will not work" :suffix-scope "/foo")
(check-conditions
'((introspection-protocol-error
"not conform to the RESPONSE role within the INTROSPECTION protocol"
"Malformed participant scope"
"Could not parse \"foo\" as UUID")))
;; Invalid payloads
(send-introspection-event
"this will not work"
:suffix-scope (format nil "/~A" (uuid:make-null-uuid)))
(check-conditions
'((introspection-protocol-error
"not conform to the RESPONSE role within the INTROSPECTION protocol"
"Payload is" "\"this will not work\""
"(not RSB.PROTOCOL.INTROSPECTION:HELLO or RSB.PROTOCOL.INTROSPECTION:BYE or \"pong\")")))
(send-introspection-event
1 :suffix-scope (format nil "/~A" (uuid:make-null-uuid)))
(check-conditions
'((introspection-protocol-error
"not conform to the RESPONSE role within the INTROSPECTION protocol"
"Payload is" "1"
"(not RSB.PROTOCOL.INTROSPECTION:HELLO or RSB.PROTOCOL.INTROSPECTION:BYE or \"pong\")"))))))
(addtest (remote-introspection-root
:documentation
"Test change-hook of the `remote-introspection' class.")
change-hook
(let+ ((calls '())
((&flet record (&rest event)
(appendf calls (list event))))
((&flet on-host-change (object subject event)
(record object subject event)
(flet ((hook () (database-change-hook subject)))
(case event
(:process-added (hooks:add-to-hook (hook) (curry #'record subject)))
(:process-removed (hooks:clear-hook (hook)))))))
((&flet on-database-change (subject event)
(record :database subject event)
(flet ((hook () (database-change-hook subject)))
(case event
(:host-added (hooks:add-to-hook (hook) (curry #'on-host-change subject)))
(:host-removed (hooks:clear-hook (hook)))))))
((&flet check-calls (expected)
(let+ (((&flet+ check-call
((call-object call-subject call-event)
(expected-object expected-subject expected-event))
(ensure (typep call-object expected-object)
:report "~@<Object ~A is not of type ~S~@:>"
:arguments (call-object expected-object))
(ensure (typep call-subject expected-subject)
:report "~@<Subject ~A is not of type ~S~@:>"
:arguments (call-subject expected-subject))
(ensure (typep call-event expected-event)
:report "~@<Event ~A is not of type ~S~@:>"
:arguments (call-event expected-event))))
(num-calls (length calls))
(num-expected (length expected)))
(ensure-same num-calls num-expected
:report "~@<~D call~:P but expected ~D~:@>"
:arguments (num-calls num-expected))
(mapc #'check-call calls expected))
(setf calls '()))))
(with-participant (introspection :remote-introspection +introspection-scope+
:change-handler #'on-database-change
:update-interval nil
:response-timeout .01)
;; Create and destroy an `informer' participant and check the
;; generated events.
(with-participant (informer :informer "/rsbtest/remote-introspection/change-hook/participant")
(declare (ignore informer)))
(check-calls
'(((eql :database) host-entry (eql :host-added))
(host-entry process-entry (eql :process-added))
(process-entry participant-entry (eql :participant-added))
(process-entry participant-entry (eql :participant-removed))
(host-entry process-entry (eql :process-removed))
(host-entry (eql :unknown) (eql :state-changed))))
;; Test clock-offset and latency events.
(with-participant (informer :informer "/rsbtest/remote-introspection/change-hook/timing")
(declare (ignore informer))
(setf calls '())
(dotimes (i 4) (rsb.ep:handle introspection :update))
(check-calls
'((process-entry real (eql :clock-offset-changed))
(process-entry real (eql :latency-changed))
(host-entry real (eql :clock-offset-changed))
(host-entry real (eql :latency-changed))))))))
(addtest (remote-introspection-root
:documentation
"Stress test which sends introspection events to a
`remote-introspection' instance from multiple threads in
parallel.")
stress
(with-participants ((nil :remote-introspection +introspection-scope+
:update-interval .01)
(introspection :local-introspection +introspection-scope+))
(let+ ((configuration *configuration*)
((&flet participant-noise ()
(let ((*configuration* configuration)
(*local-database* introspection))
(iter (repeat 30)
(sleep (random .01))
(with-participant (server :local-server (string (gensym "/")))
(with-methods (server)
(("echo" (x) x) ("echo2" (x) x) ("echo3" (x) x))))))))
(threads (map-into (make-list 10) (curry #'bt:make-thread
#'participant-noise))))
(mapc #'bt:join-thread threads))))
| 10,763 | Common Lisp | .lisp | 220 | 38.890909 | 102 | 0.626071 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | b9286156ca8e3fbc6a41570eb82de6fa824c09e0f4d3f56ad913d4bc8d6e29c2 | 25,199 | [
-1
] |
25,200 | timing-tracking.lisp | open-rsx_rsb-cl/test/introspection/timing-tracking.lisp | ;;;; timing-tracking.lisp --- Unit tests for the timing tracking functionality.
;;;;
;;;; Copyright (C) 2014 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.introspection.test)
(deftestsuite timing-tracking-root (introspection-root)
()
(:documentation
"Unit test suite for the timing tracking functionality."))
(deftestsuite timing-tracker-root (timing-tracking-root)
()
(:documentation
"Unit test suite for the `timing-tracker' class."))
(addtest (timing-tracker-root
:documentation
"Smoke test for the `timing-tracker' class.")
smoke
(let* ((tracker (make-instance 'rsb.introspection::timing-tracker))
(event (rsb:make-event
"/" 1
:timestamps `(:request.send ,(local-time:parse-timestring
"2014-10-06T08:03:16.000000+02:00")
:request.receive ,(local-time:parse-timestring
"2014-10-06T08:03:16.001000+02:00")
:send ,(local-time:parse-timestring
"2014-10-06T08:03:16.003000+02:00")
:receive ,(local-time:parse-timestring
"2014-10-06T08:03:16.004000+02:00")))))
(loop :repeat 10 :do (rsb.ep:handle tracker event))
(ensure-same 0 (rsb.introspection::timing-tracker-clock-offset tracker)
:test #'=)
(ensure-same 0.001d0 (rsb.introspection::timing-tracker-latency tracker)
:test #'=)))
| 1,708 | Common Lisp | .lisp | 34 | 36.205882 | 91 | 0.547034 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | bd0e836fcc653b3feae5d2bef6278ba29dc8df0884db033e289865dd0d4c9464 | 25,200 | [
-1
] |
25,201 | platform.lisp | open-rsx_rsb-cl/test/introspection/platform.lisp | ;;;; package.lisp --- Package definition for unit tests of the introspection module.
;;;;
;;;; Copyright (C) 2014 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.introspection.test)
(deftestsuite introspection-platform-root (introspection-root)
()
(:documentation
"Unit tests for the platform information functions."))
(addtest (introspection-platform-root
:documentation
"Smoke test for the process information functions.")
process-info/smoke
(ensure (typep (current-process-id) 'non-negative-integer))
(ensure (typep (current-program-name-and-commandline-arguments)
'list))
(ensure (typep (current-process-start-time) 'local-time:timestamp)))
(addtest (introspection-platform-root
:documentation
"Smoke test for the host information functions.")
host-info/smoke
(ensure (typep (current-host-id) 'string)))
| 951 | Common Lisp | .lisp | 23 | 36.782609 | 84 | 0.714751 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | be43c1baa3ac60f46e3c98199032cdb6720cfdae0650ef948d5b367edb91644c | 25,201 | [
-1
] |
25,202 | meta-data-filter.lisp | open-rsx_rsb-cl/test/filter/meta-data-filter.lisp | ;;;; meta-data-filter.lisp --- Unit tests for meta-data-filter class.
;;;;
;;;; Copyright (C) 2015, 2016 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.filter.test)
(deftestsuite meta-data-filter-root (filter-root)
()
(:documentation
"Test suite for the `meta-data-filter' class."))
(define-basic-filter-tests (meta-data-filter :meta-data)
;; Construct cases
`((() error) ; missing initargs
((:key :foo) error) ; missing :predicate initarg
((:predicate 'emptyp) error) ; missing :key initarg
;; these are ok
((:key :foo :predicate emptyp) t)
((:key :foo :predicate ,#'emptyp) t)))
(define-filter-match-test (meta-data-filter :meta-data)
`(((:key :foo :predicate ,(curry #'eql 1)) ("/" 1) nil)
((:key :foo :predicate ,(curry #'eql 1)) ("/" 1 :foo 2) nil)
((:key :foo :predicate ,(curry #'eql 1)) ("/" 1 :foo 1) t)))
| 988 | Common Lisp | .lisp | 22 | 41.818182 | 73 | 0.594173 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | bb6b2d86c43c86c323b8973dfea7583c0770422fb9489e851e148e9f440169e6 | 25,202 | [
-1
] |
25,203 | package.lisp | open-rsx_rsb-cl/test/filter/package.lisp | ;;;; package.lisp --- Package definition for unit tests of the filter module.
;;;;
;;;; Copyright (C) 2011-2016 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:defpackage #:rsb.filter.test
(:use
#:cl
#:alexandria
#:let-plus
#:lift
#:rsb
#:rsb.filter
#:rsb.test)
(:export
#:define-basic-filter-tests
#:define-filter-match-test)
(:documentation
"This package contains unit tests for the filter module."))
(cl:in-package #:rsb.filter.test)
(deftestsuite filter-root (root)
()
(:documentation
"Root unit test suite for the filter module."))
;;; Utilities
(defun call-with-filter-checking-thunk
(thunk filter event-spec)
"Call THUNK with a function as the sole argument, that
1. Constructs an `access-checking-event' according to EVENT-SPEC
2. Applies FILTER rule to the event
3. Returns the matching result"
(let+ (((&flet check (funcall?)
(let+ ((event (apply #'make-access-checking-event-for-processor
filter event-spec))
((&flet do-it ()
(with-access-checking ()
(if funcall?
(funcall filter event)
(matches? filter event))))))
(funcall thunk #'do-it)))))
(check nil)
(check t)))
(defmacro define-basic-filter-tests
((class spec
&key
(suite-name (symbolicate class "-ROOT")))
construct-cases)
"Define basic test cases for the filter class CLASS."
`(progn
(addtest (,suite-name
:documentation
,(format nil "Test construction instances of the ~
`~(~A~)' filter class."
class))
construct
(ensure-cases (args expected)
,construct-cases
(case expected
(error
(ensure-condition error
(apply #'make-instance ',class args)))
(t
(apply #'make-instance ',class args)
(apply #'make-filter ,spec args)
(apply #'filter ,spec args)))))
(addtest (,suite-name
:documentation
,(format nil "Test method on `print-object' for the ~
`~(~A~)' filter class."
class))
print
(mapc (lambda+ ((initargs &ign))
(check-print (apply #'make-filter ,spec initargs)))
(remove t ,construct-cases :key #'second :test-not #'eq)))))
(defmacro define-filter-match-test
((class spec
&key
(suite-name (symbolicate class "-ROOT")))
cases)
"Define a test case for the `matches?' method of filter class
CLASS."
`(addtest (,suite-name
:documentation
,(format nil "Smoke test for the `~(~A~)' filter class."
class))
smoke
(ensure-cases (filter-initargs event-spec expected)
,cases
(let ((filter (apply #'filter (if (listp (first filter-initargs))
(list (list* ,spec filter-initargs))
(list* ,spec filter-initargs)))))
(call-with-filter-checking-thunk
(lambda (do-it)
(let ((result (funcall do-it)))
(ensure-same result expected
:report "~@<The filter ~S ~:[did not ~
match~;matched~] the event ~S, ~
but should~:[ not~;~].~@:>"
:arguments (filter result event-spec expected))))
filter
event-spec)))))
| 3,699 | Common Lisp | .lisp | 101 | 25.683168 | 77 | 0.534059 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | bbafd541911bf2658da3836e055e85c642441f6cac8e061df3bfb87437c2d19f | 25,203 | [
-1
] |
25,204 | protocol.lisp | open-rsx_rsb-cl/test/filter/protocol.lisp | ;;;; protocol.lisp --- Unit tests for the filter module protocol functions.
;;;;
;;;; Copyright (C) 2011, 2012, 2013 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.filter.test)
(deftestsuite protocol-root (filter-root)
()
(:documentation
"Unit test suite for the protocol functions of the filter module
protocol."))
(addtest (protocol-root
:documentation
"Smoke test for the `filter' function.")
filter-smoke
;; No such filter class.
(ensure-condition 'filter-construction-error
(filter :no-such-filter))
;; Missing initarg.
(ensure-condition 'filter-construction-error
(filter :origin))
;; Illegal initarg.
(ensure-condition 'filter-construction-error
(filter :origin :origin 5)))
| 793 | Common Lisp | .lisp | 24 | 29.666667 | 75 | 0.715033 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 96c9418f85ed1a324489a7c85800dba1c928b861a9f80f98280231c9822d3e0f | 25,204 | [
-1
] |
25,205 | composite-filter.lisp | open-rsx_rsb-cl/test/filter/composite-filter.lisp | ;;;; composite-filter.lisp --- Unit test for composite filter classes.
;;;;
;;;; Copyright (C) 2011-2016 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.filter.test)
;;; `complement-filter'
(deftestsuite complement-filter-root (filter-root)
()
(:documentation
"Unit tests for the `complement-filter' class."))
(define-basic-filter-tests (complement-filter :complement)
`(;; exactly one child is required.
(() error)
((:children ()) error)
((:children (,#1=(filter :scope :scope "/bar") ,#1#)) error)
;; these are ok
((:children (,(filter :scope :scope "/bar"))) t)))
(define-filter-match-test (complement-filter :complement)
'((((:type :type integer)) ("/" "bar") t)
(((:type :type integer)) ("/" 1) nil)))
;;; `conjoin-filter'
(deftestsuite conjoin-filter-root (filter-root)
()
(:documentation
"Unit tests for the `conjoin-filter' class."))
(define-basic-filter-tests (conjoin-filter :and)
'(;; these are ok
(() t)
((:children ()) t)))
(define-filter-match-test (conjoin-filter :and)
'((() ("/" "bar") t)
(((:type :type string)) ("/" "bar") t)
(((:type :type string)) ("/" 1) nil)
(((:type :type string) (:scope :scope "/foo")) ("/" "bar") nil)
(((:type :type string) (:scope :scope "/foo")) ("/" 1) nil)
(((:type :type string) (:scope :scope "/foo")) ("/foo/bar" "baz") t)
(((:type :type string) (:scope :scope "/foo")) ("/foo/bar" 1) nil)))
;;; `disjoin-filter'
(deftestsuite disjoin-filter-root (filter-root)
()
(:documentation
"Unit tests for the `disjoin-filter' class."))
(define-basic-filter-tests (disjoin-filter :or)
'(;; these are ok
(() t)
((:children ()) t)))
(define-filter-match-test (disjoin-filter :or)
'((() ("/" "bar") nil)
(((:type :type string)) ("/" "bar") t)
(((:type :type string)) ("/" 1) nil)
(((:type :type string) (:scope :scope "/foo")) ("/" "bar") t)
(((:type :type string) (:scope :scope "/foo")) ("/" 1) nil)
(((:type :type string) (:scope :scope "/foo")) ("/foo/bar" "baz") t)
(((:type :type string) (:scope :scope "/foo")) ("/foo/bar" 1) t)))
| 2,613 | Common Lisp | .lisp | 55 | 43.981818 | 79 | 0.489764 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | f11db6009efed45a262c7c6f5e16be0a397d2373b17284d62e41b468ec2c3686 | 25,205 | [
-1
] |
25,206 | origin-filter.lisp | open-rsx_rsb-cl/test/filter/origin-filter.lisp | ;;;; origin-filter.lisp --- Unit tests for origin filter.
;;;;
;;;; Copyright (C) 2012, 2014, 2016 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.filter.test)
(deftestsuite origin-filter-root (filter-root)
()
(:documentation
"Test suite for the `origin-filter' class."))
(define-basic-filter-tests (origin-filter :origin)
`(;; Some invalid cases.
(() error) ; missing initarg
((:origin 5) error) ; wrong origin for origin specifier
((:origin "00000000-0000-0000-0000-") error) ; UUID syntax error
;; These are ok.
((:origin ,(uuid:make-null-uuid)) t)
((:origin "00000000-0000-0000-0000-000000000000") t)
((:origin ,(uuid:uuid-to-byte-array (uuid:make-null-uuid))) t)))
(define-filter-match-test (origin-filter :origin)
`(;; Events without UUID
((:origin ,(uuid:make-null-uuid)) ("/" nil) nil)
((:origin ,(uuid:make-v4-uuid)) ("/" nil) nil)
;; Events with UUID
((:origin ,(uuid:make-null-uuid))
("/" nil :origin ,(uuid:make-null-uuid))
t)
((:origin ,(uuid:make-null-uuid))
("/" nil :origin ,(uuid:make-v4-uuid))
nil)
((:origin ,(uuid:make-v4-uuid))
("/" nil :origin ,(uuid:make-null-uuid))
nil)))
| 1,411 | Common Lisp | .lisp | 33 | 38.787879 | 106 | 0.560816 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 1639f925bc01f22c12ea9eebb0b2b527f124b2b809d0363ad770d39ddac70779 | 25,206 | [
-1
] |
25,207 | method-filter.lisp | open-rsx_rsb-cl/test/filter/method-filter.lisp | ;;;; method-filter.lisp --- Unit tests for the method-filter class.
;;;;
;;;; Copyright (C) 2011-2016 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.filter.test)
(deftestsuite method-filter-root (filter-root)
()
(:documentation
"Test suite for the `method-filter' class."))
(define-basic-filter-tests (method-filter :method)
'(;; missing :method initarg
(() error)
;; these are ok
((:method nil) t)
((:method :method) t)
((:method :|method|) t)))
(define-filter-match-test (method-filter :method)
`(((:method :foo) ("/" 1) nil)
((:method :foo) ("/" 1 :method :bar) nil)
((:method :foo) ("/" 1 :method :foo) t)))
| 748 | Common Lisp | .lisp | 21 | 32.52381 | 67 | 0.602493 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | dca650f2dc1c5c73fb803c6b8d3fad8f7f3b69185d248f9869d0e358ba06969d | 25,207 | [
-1
] |
25,208 | scope-filter.lisp | open-rsx_rsb-cl/test/filter/scope-filter.lisp | ;;;; scope-filter.lisp --- Unit tests for the scope-filter class.
;;;;
;;;; Copyright (C) 2011, 2012, 2013, 2014, 2016 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.filter.test)
(deftestsuite scope-filter-root (filter-root)
()
(:documentation
"Unit tests for the `scope-filter' class."))
(define-basic-filter-tests (scope-filter :scope)
'(;; errors
(() error) ; missing required initargs
((:scope "<>!") error) ; invalid scope
;; these are ok
((:scope "/foo") t)
((:scope "/foo" :exact? nil) t)
((:scope "/foo" :exact? t) t)))
(define-filter-match-test (scope-filter :scope)
'(((:scope "/foo") ("/" 1) nil)
((:scope "/foo") ("/foo" 1) t)
((:scope "/foo") ("/foo/bar" 1) t)
((:scope "/foo":exact? t) ("/" 1) nil)
((:scope "/foo":exact? t) ("/foo" 1) t)
((:scope "/foo":exact? t) ("/foo/bar" 1) nil)))
| 1,034 | Common Lisp | .lisp | 25 | 37.96 | 67 | 0.51992 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | c9bc593f1f6b4ecb494b9a3e9996969ed5c780235b62aa49e9fce0a24e4ca62b | 25,208 | [
-1
] |
25,209 | xpath-filter.lisp | open-rsx_rsb-cl/test/filter/xpath-filter.lisp | ;;;; xpath-filter.lisp --- Unit tests for the xpath-filter class.
;;;;
;;;; Copyright (C) 2015, 2016, 2017 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.filter.test)
(deftestsuite xpath-filter-root (filter-root)
()
(:documentation
"Unit tests for the `xpath-filter' class."))
(define-basic-filter-tests (xpath-filter :xpath)
'(;; Some invalid cases.
(() error) ; missing initarg
((:xpath 5) error) ; wrong type for XPath
((:xpath ".*") error) ; invalid XPath
;; These are ok.
((:xpath "*") t)
((:xpath "*" :namespaces (("" . "http://foo"))) t)
((:xpath "*" :builder t) t)))
(define-filter-match-test (xpath-filter :xpath)
`(((:xpath "@no-such-attribute") ("/" "bar") nil)
((:xpath "no-such-node") ("/" "bar") nil)
((:xpath "*") ("/" "bar") t)
((:xpath ".//*") ("/" "bar") t)
((:xpath "@scope") ("/foo" "bar") t)
((:xpath "contains(@scope, \"foo\")") ("/foo" "bar") t)
((:xpath "contains(@scope, \"bar\")") ("/foo" "bar") nil)
((:xpath "not(@origin)") ("/" "bar") t)
((:xpath "@origin")
("/" "bar" :origin ,(uuid:make-null-uuid))
t)
((:xpath "not(@sequence-number)") ("/" "bar") t)
((:xpath "@sequence-number > 0") ("/" "bar" :sequence-number 10) t)
((:xpath "not(@method)") ("/" "bar") t)
((:xpath "@method") ("/" "bar" :method :|foo|) t)
((:xpath "@method = 'foo'") ("/" "bar" :method :|foo|) t)
((:xpath "data/node()") ("/" "bar") t)
((:xpath "data/node() = 'bar'") ("/" "bar") t)
((:xpath "meta-data/node()") ("/" "bar") nil)
((:xpath "meta-data[@key='foo']/node()") ("/" "bar" :|foo| "a") t)
((:xpath "timestamp[@key='CREATE']/node()") ("/" "bar") t)
((:xpath "cause/node()") ("/" "bar") nil)
((:xpath "cause/node()")
("/" "bar" :causes (,(cons (uuid:make-null-uuid) 0)))
t)
;; Some functions and operators.
((:xpath "count(cause) = 0") ("/" "bar") t)
((:xpath "contains(data/node(), 'ar')") ("/" "bar") t)
((:xpath "contains(data/node(), 'az')") ("/" "bar") nil)
((:xpath "data/node() = 0") ("/" 0) t)))
| 3,103 | Common Lisp | .lisp | 50 | 57.6 | 87 | 0.354393 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | dbbba99b96dfdc5322409b499fe58756cc848bfc7558609c89186314ace52bf7 | 25,209 | [
-1
] |
25,210 | cause-filter.lisp | open-rsx_rsb-cl/test/filter/cause-filter.lisp | ;;;; cause-filter.lisp --- Unit tests for the cause-filter class.
;;;;
;;;; Copyright (C) 2016 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.filter.test)
(deftestsuite cause-filter-root (filter-root)
()
(:documentation
"Test suite for the `cause-filter' class."))
(define-basic-filter-tests (cause-filter :cause)
`(;; Some invalid cases.
(() error) ; missing initarg
((:cause 5) error) ; wrong cause for cause specifier
((:cause "00000000-0000-0000-0000-") error) ; UUID syntax error
((:cause "00000000-0000-0000-0000-000000000000"
:origin"00000000-0000-0000-0000-000000000000")
error) ; incompatible initargs
((:cause "00000000-0000-0000-0000-000000000000"
:sequence-number 0)
error) ; incompatible initargs
;; These are ok.
((:cause t) t)
((:cause ,(uuid:make-null-uuid)) t)
((:cause "00000000-0000-0000-0000-000000000000") t)
((:cause ,(uuid:uuid-to-byte-array (uuid:make-null-uuid))) t)
((:cause ,(cons (uuid:make-null-uuid) 0)) t)
((:origin ,(uuid:make-null-uuid)) t)
((:origin "00000000-0000-0000-0000-000000000000") t)
((:origin ,(uuid:uuid-to-byte-array (uuid:make-null-uuid))) t)
((:sequence-number 0) t)))
(define-filter-match-test (cause-filter :cause)
`(;; Events without UUID
((:cause t) ("/" nil) nil)
((:cause ,(uuid:make-null-uuid)) ("/" nil) nil)
((:cause ,(uuid:make-v4-uuid)) ("/" nil) nil)
;; Events with UUID
((:cause t)
("/" nil :causes (,(cons (uuid:make-v4-uuid) 0)))
t)
((:cause ,(uuid:make-v4-uuid))
("/" nil :causes (,(cons (uuid:make-null-uuid) 0)))
nil)
((:cause ,(event-id->uuid (cons (uuid:make-null-uuid) 0)))
("/" nil :causes (,(cons (uuid:make-null-uuid) 0)))
t)
((:cause ,(cons (uuid:make-null-uuid) 1))
("/" nil :causes (,(cons (uuid:make-null-uuid) 0)))
nil)
((:cause ,(cons (uuid:make-null-uuid) 1))
("/" nil :causes (,(cons (uuid:make-null-uuid) 1)))
t)
((:origin ,(uuid:make-null-uuid)
:sequence-number 0)
("/" nil :causes (,(cons (uuid:make-null-uuid) 0)))
t)
((:origin ,(uuid:make-null-uuid))
("/" nil :causes (,(cons (uuid:make-v4-uuid) 0)))
nil)
((:origin ,(uuid:make-null-uuid))
("/" nil :causes (,(cons (uuid:make-null-uuid) 0)))
t)
((:sequence-number 1)
("/" nil :causes (,(cons (uuid:make-null-uuid) 0)))
nil)
((:sequence-number 1)
("/" nil :causes (,(cons (uuid:make-null-uuid) 1)))
t)))
| 3,027 | Common Lisp | .lisp | 68 | 37.838235 | 104 | 0.50611 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | b9ed4e2b8555b9aca73b05232e652878401b3763d08f808f6846a2743375f457 | 25,210 | [
-1
] |
25,211 | type-filter.lisp | open-rsx_rsb-cl/test/filter/type-filter.lisp | ;;;; type-filter.lisp --- Unit tests for the type-filter class.
;;;;
;;;; Copyright (C) 2016 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.filter.test)
(deftestsuite type-filter-root (filter-root)
()
(:documentation
"Unit tests for the `type-filter' class."))
(define-basic-filter-tests (type-filter :type)
'(;; Some invalid cases.
(() error) ; missing initarg
((:type 5) error) ; wrong type for type specifier
;; These are ok.
((:type t) t)
((:type integer) t)))
(define-filter-match-test (type-filter :type)
'(((:type t) ("/" "bar") t)
((:type integer) ("/" "bar") nil)
((:type string) ("/" "bar") t)
((:type integer) ("/" 5) t)
((:type string) ("/" 5) nil)))
| 810 | Common Lisp | .lisp | 23 | 31.956522 | 63 | 0.580563 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 1763af493ffd4f7fa698f0a7fe49fea31e0e289b0997998f8a5ea4a461232cc6 | 25,211 | [
-1
] |
25,212 | regex-filter.lisp | open-rsx_rsb-cl/test/filter/regex-filter.lisp | ;;;; regex-filter.lisp --- Unit tests for the regex-filter class.
;;;;
;;;; Copyright (C) 2015, 2016 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.filter.test)
(deftestsuite regex-filter-root (filter-root)
()
(:documentation
"Unit tests for the `regex-filter' class."))
(define-basic-filter-tests (regex-filter :regex)
'(;; Some invalid cases.
(() error) ; missing initarg
((:regex 5) error) ; wrong type for regex
((:regex "*") error) ; invalid regex
;; These are ok.
((:regex ".*") t)
((:regex ".*" :always :match) t)
((:regex ".*" :case-sensitive? t) t)))
(define-filter-match-test (regex-filter :regex)
'(((:regex "^bar$") ("/" "bar") t)
((:regex "^bar$") ("/" "BAR") nil)
((:regex "^bar$") ("/" "baz") nil)
((:regex "^bar$") ("/" "BAZ") nil)
((:regex "^bar$" :case-sensitive? nil) ("/" "bar") t)
((:regex "^bar$" :case-sensitive? nil) ("/" "BAR") t)
((:regex "^bar$" :case-sensitive? nil) ("/" "baz") nil)
((:regex "^bar$" :case-sensitive? nil) ("/" "BAZ") nil)
((:regex ".*") ("/" 1) t)
((:regex ".*" :always :do-not-match) ("/" 1) nil)))
| 1,396 | Common Lisp | .lisp | 30 | 42.766667 | 67 | 0.472018 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 70df66eef353fedb02c9127a25209bc6dd7b3069511b773cfd255d521c984856 | 25,212 | [
-1
] |
25,213 | package.lisp | open-rsx_rsb-cl/test/converter/package.lisp | ;;;; package.lisp --- Package definition for unit tests of the converter module.
;;;;
;;;; Copyright (C) 2011-2016 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:defpackage #:rsb.converter.test
(:use
#:cl
#:alexandria
#:let-plus
#:more-conditions
#:lift
#:nibbles
#:rsb
#:rsb.converter
#:rsb.test)
(:export
#:converter-root
#:octetify
#:define-basic-converter-test-cases)
;; Test utilities
(:export
#:call-tracking-converter
#:converter-next
#:converter-calls)
(:documentation
"This package contains unit tests for the converter module."))
(cl:in-package #:rsb.converter.test)
(deftestsuite converter-root (root)
()
(:function
(octetify (value)
(coerce value 'simple-octet-vector)))
(:documentation
"Root unit test suite for the converter module."))
(defmacro define-basic-converter-test-cases
((converter
&key
(suite-name (symbolicate converter "-ROOT"))
(make-converter converter)
(domain-test 'equalp)
(simple? t))
cases)
"Emit basic test cases for CONVERTER in test suite SUITE-NAME."
`(progn
(addtest (,suite-name
:documentation
,(format nil "Test methods on `wire->domain?' for the `~(~A~)' converter."
converter))
wire->domain-applicability
(ensure-cases (wire-data wire-schema domain-object)
,cases
(let+ ((converter ,make-converter)
((&flet do-it ()
(wire->domain? converter wire-data wire-schema))))
(cond
((member wire-data '(:error :not-applicable)))
((eq domain-object :not-applicable)
(ensure-null (do-it)))
(t
,(if simple?
`(ensure-same (do-it) converter :ignore-multiple-values? t)
`(ensure (do-it))))))))
(addtest (,suite-name
:documentation
,(format nil "Test methods on `domain->wire?' for the `~(~A~)' converter."
converter))
domain->wire-applicability
(ensure-cases (wire-data wire-schema domain-object)
,cases
(let+ ((converter ,make-converter)
((&flet do-it ()
(domain->wire? converter domain-object))))
(cond
((member domain-object '(:error :not-applicable)))
((eq wire-data :not-applicable)
(ensure-null (do-it)))
(t
(let+ (((&values converter* wire-type* wire-schema*) (do-it)))
,(if simple?
`(ensure-same converter converter*)
`(ensure converter*))
(unless (eq wire-data :error)
(ensure (typep wire-data wire-type*)))
(ensure-same wire-schema wire-schema*)))))))
(addtest (,suite-name
:documentation
,(format nil "Test methods on `wire->domain' for the `~(~A~)' converter."
converter))
wire->domain-smoke
(ensure-cases (wire-data wire-schema domain-object)
,cases
(let+ ((converter ,make-converter)
((&flet do-it ()
(wire->domain converter wire-data wire-schema))))
(cond
((member wire-data '(:error :not-applicable)))
((member domain-object '(:error :not-applicable))
(ensure-condition 'error (do-it)))
(t
(ensure-same (do-it) domain-object
:test (function ,domain-test)))))))
(addtest (,suite-name
:documentation
,(format nil "Test methods on `domain->wire' for the `~(~A~)' converter."
converter))
domain->wire-smoke
(ensure-cases (wire-data wire-schema domain-object)
,cases
(let+ ((converter ,make-converter)
((&flet do-it ()
(domain->wire converter domain-object))))
(cond
((member domain-object '(:error :not-applicable)))
((member wire-data '(:error :not-applicable))
(ensure-condition 'error (do-it)))
(t
(ensure-same (do-it) (values wire-data wire-schema)
:test #'equalp))))))
(addtest (,suite-name
:documentation
,(format nil "Roundtrip test for the `~(~A~)' converter."
converter))
roundtrip
(ensure-cases (wire-data wire-schema domain-object)
,cases
(unless (or (member wire-data '(:error :not-applicable))
(member domain-object '(:error :not-applicable)))
(let+ ((converter ,make-converter)
((&values encoded encoded-wire-schema)
(domain->wire converter domain-object))
(decoded (wire->domain converter encoded encoded-wire-schema)))
(ensure-same domain-object decoded
:test (function ,domain-test))))))))
;;; `tracking-converter'
(defclass call-tracking-converter ()
((next :initarg :next
:reader converter-next
:documentation
"The subordinate converter to delegate the actual work to.")
(calls :type list
:reader converter-calls
:accessor converter-%calls
:initform '()
:documentation
"A list of calls to converter-protocol-related functions."))
(:default-initargs
:next (missing-required-initarg 'call-tracking-converter :next))
(:documentation
"A converter that tracks convert-protocol-related calls but
otherwise delegates to a subordinate converter."))
(macrolet ((define-call-tracking-method (name lambda-list)
(let* ((unspecialized
(mapcar (compose #'first #'ensure-list)
(parse-ordinary-lambda-list
lambda-list :allow-specializers t)))
(converter (first unspecialized)))
`(defmethod ,name ,lambda-list
(push `(,',name ,,@unspecialized)
(converter-%calls ,converter))
(,name (converter-next ,converter)
,@(rest unspecialized))))))
(define-call-tracking-method wire->domain?
((converter call-tracking-converter)
(wire-data t)
(wire-schema t)))
(define-call-tracking-method domain->wire?
((converter call-tracking-converter)
(domain-object t)))
(define-call-tracking-method wire->domain
((converter call-tracking-converter)
(wire-data t)
(wire-schema t)))
(define-call-tracking-method domain->wire
((converter call-tracking-converter)
(domain-object t))))
(service-provider:register-provider/class
'rsb.converter::converter :call-tracking :class 'call-tracking-converter)
| 7,047 | Common Lisp | .lisp | 178 | 28.752809 | 89 | 0.560234 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 10e3744c49abf4e57b33cfa6ce2195d8b302909b2603c3f813da2a4ad24b651f | 25,213 | [
-1
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.