Squashed 'third_party/allwpilib/' changes from 66b57f032..e473a00f9
e473a00f9 [wpiutil] Base64: Add unsigned span/vector variants (#3702)
52f2d580e [wpiutil] raw_uv_ostream: Add reset() (#3701)
d7b1e3576 [wpiutil] WebSocket: move std::function (#3700)
93799fbe9 [examples] Fix description of TrapezoidProfileSubsystem (#3699)
b84644740 [wpimath] Document pose estimator states, inputs, and outputs (#3698)
2dc35c139 [wpimath] Fix classpaths for JNI class loads (#3697)
2cb171f6f [docs] Set Doxygen extract_all to true and fix Doxygen failures (#3695)
a939cd9c8 [wpimath] Print uncontrollable/unobservable models in LQR and KF (#3694)
d5270d113 [wpimath] Clean up C++ StateSpaceUtil tests (#3692)
b20903960 [wpimath] Remove redundant discretization tests from StateSpaceUtilTest (#3689)
c0cb545b4 [wpilibc] Add deprecated Doxygen attribute to SpeedController (#3691)
35c9f66a7 [wpilib] Rename PneumaticsHub to PneumaticHub (#3686)
796d03d10 [wpiutil] Remove unused LLVM header (#3688)
8723caf78 [wpilibj] Make Java TrapezoidProfile.Constraints an immutable class (#3687)
187f50a34 [wpimath] Catch incorrect parameters to state-space models earlier (#3680)
8d04606c4 Replace instances of frc-characterization with SysId (NFC) (#3681)
b82d4f6e5 [hal, cscore, ntcore] Use WPI common handle type base
87e34967e [wpiutil] Add synchronization primitives
e32499c54 [wpiutil] Add ParallelTcpConnector (#3655)
aa0b49228 [wpilib] Remove redundant "quick turn" docs for curvature drive (NFC) (#3674)
57301a7f9 [hal] REVPH: Start closed-loop compressor control on init (#3673)
d1842ea8f [wpilib] Improve interrupt docs (NFC) (#3679)
558151061 [wpiutil] Add DsClient (#3654)
181723e57 Replace `.to<double>()` and `.template to<double>()` with `.value()` (#3667)
6bc1db44b [commands] Add pointer overload of AddRequirements (artf6003) (#3669)
737b57ed5 [wpimath] Update to drake v0.35.0 (#3665)
4d287d1ae [build] Upgrade WPIJREArtifact to JRE 2022-11.0.12u5 (#3666)
f26eb5ada [hal] Fix another typo (get -> gets) (NFC) (#3663)
94ed275ba [hal] Fix misspelling (numer -> number) (NFC) (#3662)
ac2f44da3 [wpiutil] uv: use move for std::function (#3653)
75fa1fbfb [wpiutil] json::serializer: Optimize construction (#3647)
5e689faea [wpiutil] Import MessagePack implementation (mpack) (#3650)
649a50b40 [wpiutil] Add LEB128 byte-by-byte reader (#3652)
e94397a97 [wpiutil] Move json_serializer.h to public headers (#3646)
4ec58724d [wpiutil] uv::Tcp: Clarify SetNoDelay documentation (#3649)
8cb294aa4 [wpiutil] WebSocket: Make Shutdown() public (#3651)
2b3a9a52b [wpiutil] json: Fix map iterator key() for std::string_view (#3645)
138cbb94b [wpiutil] uv::Async: Add direct call for no-parameter specialization (#3648)
e56d6dea8 [ci] Update testbench pool image to ubuntu-latest (#3643)
43f30e44e [build] Enable comments in doxygen source files (#3644)
9e6db17ef [build] Enable doxygen preprocessor expansion of WPI_DEPRECATED (#3642)
0e631ad2f Add WPILib version to issue template (#3641)
6229d8d2f [build] Docs: set case_sense_names to false (#3392)
4647d09b5 [docs] Fix Doxygen warnings, add CI docs lint job (#3639)
4ad3a5402 [hal] Fix PWM allocation channel (#3637)
05e5feac4 [docs] Fix brownout docs (NFC) (#3638)
67df469c5 [examples] Remove old command-based templates and examples (#3263)
689e9ccfb [hal, wpilib] Add brownout voltage configuration (#3632)
9cd4bc407 [docs] Add useLocal to avoid using installer artifacts (#3634)
61996c2bb [cscore] Fix Java direct callback notifications (#3631)
6d3dd99eb [build] Update to newest native-utils (#3633)
f0b484892 [wpiutil] Fix StringMap iterator equality check (#3629)
8352cbb7a Update development build instructions for 2022 (#3616)
6da08b71d [examples] Fix Intermediate Vision Java Example description (#3628)
5d99059bf [wpiutil] Remove optional.h (#3627)
fa41b106a [glass, wpiutil] Add missing format args (#3626)
4e3fd7d42 [build] Enable Zc:__cplusplus for Windows (#3625)
791d8354d [build] Suppress deprecation/removal warnings for old commands (#3618)
10f19e6fc [hal, wpilib] Add REV PneumaticsHub (#3600)
4c61a1305 [ntcore] Revert to per-element copy for toNative() (#3621)
7b3f62244 [wpiutil] SendableRegistry: Print exception stacktrace (#3620)
d347928e4 [hal] Use better error for when console out is enabled while attempting to use onboard serial port (#3622)
cc31079a1 [hal] Use setcap instead of setuid for setting thread priorities (#3613)
4676648b7 [wpimath] Upgrade to Drake v0.34.0 (#3607)
c7594c911 [build] Allow building wpilibc in cmake without cscore and opencv (#3605)
173cb7359 [wpilib] Add TimesliceRobot (#3502)
af295879f [hal] Set error status for I2C port out of range (#3603)
95dd20a15 [build] Enable spotbugs (#3601)
b65fce86b [wpilib] Remove Timer lock in wpilibj and update docs (#3602)
3b8d3bbcb Remove unused and add missing deprecated.h includes (#3599)
f9e976467 [examples] Rename DriveTrain classes to Drivetrain (#3594)
118a27be2 [wpilib] Add Timer tests (#3595)
59c89428e [wpilib] Deprecate Timer::HasPeriodPassed() (#3598)
202ca5e78 Force C++17 in .clang-format (#3597)
d6f185d8e Rename tests for consistency (#3592)
54ca474db [ci] Enable asan and tsan in CI for tests that pass (#3591)
1ca383b23 Add Debouncer (#3590)
179fde3a7 [build] Update to 2022 native utils and gradle 7 (#3588)
50198ffcf [examples] Add Mechanism2d visualization to Elevator Sim (#3587)
a446c2559 [examples] Synchronize C++ and Java Mechanism2d examples (#3589)
a7fb83103 [ci] clang-tidy: Generate compilation commands DB with Gradle (#3585)
4f5e0c9f8 [examples] Update ArmSimulation example to use Mechanism2d (#3572)
8164b91dc [CI] Print CMake test output on failure (#3583)
4d5fca27e [wpilib] Impove Mechanism2D documentation (NFC) (#3584)
fe59e4b9f Make C++ test names more consistent (#3586)
5c8868549 [wpilibc] Fix C++ MechanisimRoot2D to use same NT entries as Java/Glass (#3582)
9359431ba [wpimath] Clean up Eigen usage
72716f51c [wpimath] Upgrade to Eigen 3.4
382deef75 [wpimath] Explicitly export wpimath symbols
161e21173 [ntcore] Match standard handle layout, only allow 16 instances (#3577)
263a24811 [wpimath] Use jinja for codegen (#3574)
725251d29 [wpilib] Increase tolerances of DifferentialDriveSimTest (#3581)
4dff87301 [wpimath] Make LinearFilter::Factorial() constexpr (#3579)
60ede67ab [hal, wpilib] Switch PCM to be a single object that is allowed to be duplicated (#3475)
906bfc846 [build] Add CMake build support for sanitizers (#3576)
0d4f08ad9 [hal] Simplify string copy of joystick name (#3575)
a52bf87b7 [wpiutil] Add Java function package (#3570)
40c7645d6 [wpiutil] UidVector: Return old object from erase() (#3571)
5b886a23f [wpiutil] jni_util: Add size, operator[] to JArrayRef (#3569)
65797caa7 [sim] Fix halsim_ds_socket stringop overflow warning from GCC 10 (#3568)
66abb3988 [hal] Update runtime enum to allow selecting roborio 2 (#3565)
95a12e0ee [hal] UidSetter: Don't revert euid if its already current value (#3566)
27951442b [wpimath] Use external Eigen headers only (#3564)
c42e053ae [docs] Update to doxygen 1.9.2 (#3562)
e7048c8c8 [docs] Disable doxygen linking for common words that are also classes (#3563)
d8e0b6c97 [wpilibj] Fix java async interrupts (#3559)
5e6c34c61 Update to 2022 roborio image (#3537)
828f073eb [wpiutil] Fix uv::Buffer memory leaks caught by asan (#3555)
2dd5701ac [cscore] Fix mutex use-after-free in cscore test (#3557)
531439198 [ntcore] Fix NetworkTables memory leaks caught by asan (#3556)
3d9a4d585 [wpilibc] Fix AnalogTriggerOutput memory leak reported by asan (#3554)
54eda5928 [wpiutil] Ignore ubsan vptr upcast warning in SendableHelper moves (#3553)
5a4f75c9f [wpilib] Replace Speed controller comments with motor controller (NFC) (#3551)
7810f665f [wpiutil] Fix bug in uleb128 (#3540)
697e2dd33 [wpilib] Fix errant jaguar reference in comments (NFC) (#3550)
936c64ff5 [docs] Enable -linksource for javadocs (#3549)
1ea654954 [build] Upgrade CMake build to googletest 1.11.0 (#3548)
32d9949e4 [wpimath] Move controller tests to wpimath (#3541)
01ba56a8a [hal] Replace strncpy with memcpy (#3539)
e109c4251 [build] Rename makeSim flag to forceGazebo to better describe what it does (#3535)
e4c709164 [docs] Use a doxygen theme and add logo (#3533)
960b6e589 [wpimath] Fix Javadoc warning (#3532)
82eef8d5e [hal] Remove over current fault HAL functions from REV PDH (#3526)
aa3848b2c [wpimath] Move RobotDriveBase::ApplyDeadband() to MathUtil (#3529)
3b5d0d141 [wpimath] Add LinearFilter::BackwardFiniteDifference() (#3528)
c8fc715fe [wpimath] Upgrade drake files to v0.33.0 (#3531)
e5fe3a8e1 [build] Treat javadoc warnings as errors in CI and fix warnings (#3530)
e0c6cd3dc [wpimath] Add an operator for composing two Transform2ds (#3527)
2edd510ab [sim] Add sim wrappers for sensors that use SimDevice (#3517)
2b3e2ebc1 [hal] Fix HAL Notifier thread priority setting (#3522)
ab4cb5932 [gitignore] Update gitignore to ignore bazel / clion files (#3524)
57c8615af [build] Generate spotless patch on failure (#3523)
b90317321 Replace std::cout and std::cerr with fmt::print() (#3519)
10cc8b89c [hal] [wpilib] Add initial support for the REV PDH (#3503)
5d9ae3cdb [hal] Set HAL Notifier thread as RT by default (#3482)
192d251ee [wpilibcIntegrationTests] Properly disable DMA integration tests (#3514)
031962608 [wpilib] Add PS4Controller, remove Hand from GenericHID/XboxController (#3345)
25f6f478a [wpilib] Rename DriverStation::IsOperatorControl() to IsTeleop() (#3505)
e80f09f84 [wpilibj] Add unit tests (#3501)
c159f91f0 [wpilib] Only read DS control word once in IterativeRobotBase (#3504)
eb790a74d Add rio development docs documenting myRobot deploy tasks (#3508)
e47451f5a [wpimath] Replace auto with Eigen types (#3511)
252b8c83b Remove Java formatting from build task in CI (#3507)
09666ff29 Shorten Gazebo CI build (#3506)
baf2e501d Update myRobot to use 2021 java (#3509)
5ac60f0a2 [wpilib] Remove IterativeRobotBase mode init prints (#3500)
fb2ee8ec3 [wpilib] Add TimedRobot functions for running code on mode exit (#3499)
94e0db796 [wpilibc] Add more unit tests (#3494)
b25324695 [wpilibj] Add units to parameter names (NFC) (#3497)
1ac73a247 [hal] Rename PowerDistributionPanel to PowerDistribution (#3466)
2014115bc [examples] frisbeebot: Fix typo and reflow comments (NFC) (#3498)
4a944dc39 [examples] Consistently use 0 for controller port (#3496)
3838cc4ec Use unicode characters in docs equations (#3487)
85748f2e6 [examples] Add C++ TankDrive example (#3493)
d7b8aa56d [wpilibj] Rename DriverStation In[Mode] functions to follow style guide (#3488)
16e096cf8 [build] Fix CMake Windows CI (#3490)
50af74c38 [wpimath] Clean up NumericalIntegration and add Discretization tests (#3489)
bfc209b12 Automate fmt update (#3486)
e7f9331e4 [build] Update to Doxygen 1.9.1 (#3008)
ab8e8aa2a [wpimath] Update drake with upstream (#3484)
1ef826d1d [wpimath] Fix IOException path in WPIMath JNI (#3485)
52bddaa97 [wpimath] Disable iostream support for units and enable fmtlib (#3481)
e4dc3908b [wpiutil] Upgrade to fmtlib 8.0.1 (#3483)
1daadb812 [wpimath] Implement Dormand-Prince integration method (#3476)
9c2723391 [cscore] Add [[nodiscard]] to GrabFrame functions (#3479)
7a8796414 [wpilib] Add Notifier integration tests (#3480)
f8f13c536 [wpilibcExamples] Prefix decimal numbers with 0 (#3478)
1adb69c0f [ntcore] Use "NetworkTables" instead of "Network Tables" in NT specs (#3477)
5f5830b96 Upload wpiformat diff if one exists (#3474)
9fb4f35bb [wpimath] Add tests for DARE overload with Q, R, and N matrices (#3472)
c002e6f92 Run wpiformat (#3473)
c154e5262 [wpilib] Make solenoids exclusive use, PCM act like old sendable compressor (#3464)
6ddef1cca [hal] JNI setDIO: use a boolean and not a short (#3469)
9d68d9582 Remove extra newlines after open curly braces (NFC) (#3471)
a4233e1a1 [wpimath] Add script for updating Drake (#3470)
39373c6d2 Update README.md for new GCC version requirement (#3467)
d29acc90a [wpigui] Add option to reset UI on exit (#3463)
a371235b0 [ntcore] Fix dangling pointer in logger (#3465)
53b4891a5 [wpilibcintegrationtests] Fix deprecated Preferences usage (#3461)
646ded912 [wpimath] Remove incorrect discretization in pose estimators (#3460)
ea0b8f48e Fix some deprecation warnings due to fmtlib upgrade (#3459)
2067d7e30 [wpilibjexamples] Add wpimathjni, wpiutiljni to library path (#3455)
866571ab4 [wpiutil] Upgrade to fmtlib 8.0.0 (#3457)
4e1fa0308 [build] Skip PDB copy on windows build servers (#3458)
b45572167 [build] Change CI back to 18.04 docker images (#3456)
57a160f1b [wpilibc] Fix LiveWindow deprecation warning in RobotBase skeleton template (#3454)
29ae8640d [HLT] Implement duty cycle cross connect tests (#3453)
ee6377e54 [HLT] Add relay and analog cross connects (#3452)
b0f1ae7ea [build] CMake: Build the HAL even if WITH_CSCORE=OFF (#3449)
7aae2b72d Replace std::to_string() with fmt::format() (#3451)
73fcbbd74 [HLT] Add relay digital cross connect tests (#3450)
e7bedde83 [HLT] Add PWM tests that use DMA as the back end (#3447)
7253edb1e [wpilibc] Timer: Fix deprecated warning (#3446)
efa28125c [wpilibc] Add message to RobotBase on how to read stacktrace (#3444)
9832fcfe1 [hal] Fix DIO direction getter (#3445)
49c71f9f2 [wpilibj] Clarify robot quit message (#3364)
791770cf6 [wpimath] Move controller from wpilibj to wpimath (#3439)
9ce9188ff [wpimath] Add ReportWarning to MathShared (#3441)
362066a9b [wpilib] Deprecate getInstance() in favor of static functions (#3440)
26ff9371d Initial commit of cross connect integration test project (#3434)
4a36f86c8 [hal] Add support for DMA to Java (#3158)
85144e47f [commands] Unbreak build (#3438)
b417d961e Split Sendable into NT and non-NT portions (#3432)
ef4ea84cb [commands] Change grouping decorator impl to flatten nested group structures (#3335)
b422665a3 [examples] Invert right side of drive subsystems (#3437)
186dadf14 [hal] Error if attempting to set DIO output on an input port (#3436)
04e64db94 Remove redundant C++ lambda parentheses (NFC) (#3433)
f60994ad2 [wpiutil] Rename Java package to edu.wpi.first.util (#3431)
cfa1ca96f [wpilibc] Make ShuffleboardValue non-copyable (#3430)
4d9ff7643 Fix documentation warnings generated by JavaDoc (NFC) (#3428)
9e1b7e046 [build] Fix clang-tidy and clang-format (#3429)
a77c6ff3a [build] Upgrade clang-format and clang-tidy (NFC) (#3422)
099fde97d [wpilib] Improve PDP comments (NFC) (#3427)
f8fc2463e [wpilibc, wpiutil] Clean up includes (NFC) (#3426)
e246b7884 [wpimath] Clean up member initialization in feedforward classes (#3425)
c1e128bd5 Disable frivolous PMD warnings and enable PMD in ntcore (#3419)
8284075ee Run "Lint and Format" CI job on push as well as pull request (#3412)
f7db09a12 [wpimath] Move C++ filters into filter folder to match Java (#3417)
f9c3d54bd [wpimath] Reset error covariance in pose estimator ResetPosition() (#3418)
0773f4033 [hal] Ensure HAL status variables are initialized to zero (#3421)
d068fb321 [build] Upgrade CI to use 20.04 docker images (#3420)
8d054c940 [wpiutil] Remove STLExtras.h
80f1d7921 [wpiutil] Split function_ref to a separate header
64f541325 Use wpi::span instead of wpi::ArrayRef across all libraries (#3414)
2abbbd9e7 [build] clang-tidy: Remove bugprone-exception-escape (#3415)
a5c471af7 [wpimath] Add LQR template specialization for 2x2 system
edd2f0232 [wpimath] Add DARE solver for Q, R, and N with LQR ctor overloads
b2c3b2dd8 Use std::string_view and fmtlib across all libraries (#3402)
4f1cecb8e [wpiutil] Remove Path.h (#3413)
b336eac34 [build] Publish halsim_ws_core to Maven
2a09f6fa4 [build] Also build sim modules as static libraries
0e702eb79 [hal] Add a unified PCM object (#3331)
dea841103 [wpimath] Add fmtlib formatter overloads for Eigen::Matrix and units (#3409)
82856cf81 [wpiutil] Improve wpi::circular_buffer iterators (#3410)
8aecda03e [wpilib] Fix a documentation typo (#3408)
5c817082a [wpilib] Remove InterruptableSensorBase and replace with interrupt classes (#2410)
15c521a7f [wpimath] Fix drivetrain system identification (#3406)
989de4a1b [build] Force all linker warnings to be fatal for rio builds (#3407)
d9eeb45b0 [wpilibc] Add units to Ultrasonic class API (#3403)
fe570e000 [wpiutil] Replace llvm filesystem with C++17 filesystem (#3401)
01dc0249d [wpimath] Move SlewRateLimiter from wpilib to wpimath (#3399)
93523d572 [wpilibc] Clean up integration tests (#3400)
4f7a4464d [wpiutil] Rewrite StringExtras for std::string_view (#3394)
e09293a15 [wpilibc] Transition C++ classes to units::second_t (#3396)
827b17a52 [build] Create run tasks for Glass and OutlineViewer (#3397)
a61037996 [wpiutil] Avoid MSVC warning on span include (#3393)
4e2c3051b [wpilibc] Use std::string_view instead of Twine (#3380)
50915cb7e [wpilibc] MotorSafety::GetDescription(): Return std::string (#3390)
f4e2d26d5 [wpilibc] Move NullDeleter from frc/Base.h to wpi/NullDeleter.h (#3387)
cb0051ae6 [wpilibc] SimDeviceSim: use fmtlib (#3389)
a238cec12 [wpiutil] Deprecate wpi::math constants in favor of wpi::numbers (#3383)
393bf23c0 [ntcore, cscore, wpiutil] Standardize template impl files on .inc extension (NFC) (#3124)
e7d9ba135 [sim] Disable flaky web server integration tests (#3388)
0a0003c11 [wpilibjExamples] Fix name of Java swerve drive pose estimator example (#3382)
7e1b27554 [wpilibc] Use default copies and moves when possible (#3381)
fb2a56e2d [wpilibc] Remove START_ROBOT_CLASS macro (#3384)
84218bfb4 [wpilibc] Remove frc namespace shim (#3385)
dd7824340 [wpilibc] Remove C++ compiler version static asserts (#3386)
484cf9c0e [wpimath] Suppress the -Wmaybe-uninitialized warning in Eigen (#3378)
a04d1b4f9 [wpilibc] DriverStation: Remove ReportError and ReportWarning
831c10bdf [wpilibc] Errors: Use fmtlib
87603e400 [wpiutil] Import fmtlib (#3375)
442621672 [wpiutil] Add ArrayRef/std::span/wpi::span implicit conversions
bc15b953b [wpiutil] Add std::span implementation
6d20b1204 [wpiutil] StringRef, Twine, raw_ostream: Add std::string_view support (#3373)
2385c2a43 [wpilibc] Remove Utility.h (#3376)
87384ea68 [wpilib] Fix PIDController continuous range error calculations (#3170)
04dae799a [wpimath] Add SimpleMotorFeedforward::Calculate(velocity, nextVelocity) overload (#3183)
0768c3903 [wpilib] DifferentialDrive: Remove right side inversion (#3340)
8dd8d4d2d [wpimath] Fix redundant nested math package introduced by #3316 (#3368)
49b06beed [examples] Add Field2d to RamseteController example (#3371)
4c562a445 [wpimath] Fix typo in comment of update_eigen.py (#3369)
fdbbf1188 [wpimath] Add script for updating Eigen
f1e64b349 [wpimath] Move Eigen unsupported folder into eigeninclude
224f3a05c [sim] Fix build error when building with GCC 11.1 (#3361)
ff56d6861 [wpilibj] Fix SpeedController deprecated warnings (#3360)
1873fbefb [examples] Fix Swerve and Mecanum examples (#3359)
80b479e50 [examples] Fix SwerveBot example to use unique encoder ports (#3358)
1f7c9adee [wpilibjExamples] Fix pose estimator examples (#3356)
9ebc3b058 [outlineviewer] Change default size to 600x400 (#3353)
e21b443a4 [build] Gradle: Make C++ examples runnable (#3348)
da590120c [wpilibj] Add MotorController.setVoltage default (#3347)
561d53885 [build] Update opencv to 4.5.2, imgui/implot to latest (#3344)
44ad67ca8 [wpilibj] Preferences: Add missing Deprecated annotation (#3343)
3fe8fc75a [wpilibc] Revert "Return reference from GetInstance" (#3342)
3cc2da332 Merge branch '2022'
a3cd90dd7 [wpimath] Fix classpath used by generate_numbers.py (#3339)
d6cfdd3ba [wpilib] Preferences: Deprecate Put* in favor of Set* (#3337)
ba08baabb [wpimath] Update Drake DARE solver to v0.29.0 (#3336)
497b712f6 [wpilib] Make IterativeRobotBase::m_period private with getter
f00dfed7a [wpilib] Remove IterativeRobot base class
3c0846168 [hal] Use last error reporting instead of PARAMETER_OUT_OF_RANGE (#3328)
5ef2b4fdc [wpilibj] Fix @deprecated warning for SerialPort constructor (#3329)
23d2326d1 [hal] Report previous allocation location for indexed resource duplicates (#3322)
e338f9f19 [build] Fix wpilibc runCpp task (#3327)
c8ff626fe [wpimath] Move Java classes to edu.wpi.first.math (#3316)
4e424d51f [wpilibj] DifferentialDrivetrainSim: Rename constants to match the style guide (#3312)
6b50323b0 [cscore] Use Lock2DSize if possible for Windows USB cameras (#3326)
65c148536 [wpilibc] Fix "control reaches end of non-void function" warning (#3324)
f99f62bee [wpiutil] uv Handle: Use malloc/free instead of new/delete (#3325)
365f5449c [wpimath] Fix MecanumDriveKinematics (#3266)
ff52f207c [glass, wpilib] Rewrite Mechanism2d (#3281)
ee0eed143 [wpimath] Add DCMotor factory function for Romi motors (#3319)
512738072 [hal] Add HAL_GetLastError to enable better error messages from HAL calls (#3320)
ced654880 [glass, outlineviewer] Update Mac icons to macOS 11 style (#3313)
936d3b9f8 [templates] Add Java template for educational robot (#3309)
6e31230ad [examples] Fix odometry update in SwerveControllerCommand example (#3310)
05ebe9318 Merge branch 'main' into 2022
aaf24e255 [wpilib] Fix initial heading behavior in HolonomicDriveController (#3290)
8d961dfd2 [wpilibc] Remove ErrorBase (#3306)
659b37ef9 [wpiutil] StackTrace: Include offset on Linux (#3305)
0abf6c904 [wpilib] Move motor controllers to motorcontrol package (#3302)
4630191fa [wpiutil] circular_buffer: Use value initialization instead of passing zero (#3303)
b7b178f49 [wpilib] Remove Potentiometer interface
687066af3 [wpilib] Remove GyroBase
6b168ab0c [wpilib] Remove PIDController, PIDOutput, PIDSource
948625de9 [wpimath] Document conversion from filter cutoff frequency to time constant (#3299)
3848eb8b1 [wpilibc] Fix flywhel -> flywheel typo in FlywheelSim (#3298)
3abe0b9d4 [cscore] Move java package to edu.wpi.first.cscore (#3294)
d7fabe81f [wpilib] Remove RobotDrive (#3295)
1dc81669c [wpilib] Remove GearTooth (#3293)
01d0e1260 [wpilib] Revert move of RomiGyro into main wpilibc/j (#3296)
397e569aa [ntcore] Remove "using wpi" from nt namespace
79267f9e6 [ntcore] Remove NetworkTable -> nt::NetworkTable shim
48ebe5736 [ntcore] Remove deprecated Java interfaces and classes
c2064c78b [ntcore] Remove deprecated ITable interfaces
36608a283 [ntcore] Remove deprecated C++ APIs
a1c87e1e1 [glass] LogView: Add "copy to clipboard" button (#3274)
fa7240a50 [wpimath] Fix typo in quintic spline basis matrix
ffb4d38e2 [wpimath] Add derivation for spline basis matrices
f57c188f2 [wpilib] Add AnalogEncoder(int) ctor (#3273)
8471c4fb2 [wpilib] FieldObject2d: Add setTrajectory() method (#3277)
c97acd18e [glass] Field2d enhancements (#3234)
ffb590bfc [wpilib] Fix Compressor sendable properties (#3269)
6137f98eb [hal] Rename SimValueCallback2 to SimValueCallback (#3212)
a6f653969 [hal] Move registerSimPeriodic functions to HAL package (#3211)
10c038d9b [glass] Plot: Fix window creation after removal (#3264)
2d2eaa3ef [wpigui] Ensure window will be initially visible (#3256)
4d28b1f0c [wpimath] Use JNI for trajectory serialization (#3257)
3de800a60 [wpimath] TrajectoryUtil.h: Comment formatting (NFC) (#3262)
eff592377 [glass] Plot: Don't overwrite series ID (#3260)
a79faace1 [wpilibc] Return reference from GetInstance (#3247)
9550777b9 [wpilib] PWMSpeedController: Use PWM by composition (#3248)
c8521a3c3 [glass] Plot: Set reasonable default window size (#3261)
d71eb2cf3 [glass] Plot: Show full source name as tooltip and in popup (#3255)
160fb740f [hal] Use std::lround() instead of adding 0.5 and truncating (#3012)
48e9f3951 [wpilibj] Remove wpilibj package CameraServer (#3213)
8afa596fd [wpilib] Remove deprecated Sendable functions and SendableBase (#3210)
d3e45c297 [wpimath] Make C++ geometry classes immutable (#3249)
2c98939c1 [glass] StringChooser: Don't call SameLine() at end
a18a7409f [glass] NTStringChooser: Clear value of deleted entries
2f19cf452 [glass] NetworkTablesHelper: listen to delete events
da96707dc Merge branch 'main' into 2022
c3a8bdc24 [build] Fix clang-tidy action (#3246)
21624ef27 Add ImGui OutlineViewer (#3220)
1032c9b91 [wpiutil] Unbreak wpi::Format on Windows (#3242)
2e07902d7 [glass] NTField2D: Fix name lookup (#3233)
6e23e1840 [wpilibc] Remove WPILib.h (#3235)
3e22e4506 [wpilib] Make KoP drivetrain simulation weight 60 lbs (#3228)
79d1bd6c8 [glass] NetworkTablesSetting: Allow disable of server option (#3227)
fe341a16f [examples] Use more logical elevator setpoints in GearsBot (#3198)
62abf46b3 [glass] NetworkTablesSettings: Don't block GUI (#3226)
a95a5e0d9 [glass] Move NetworkTablesSettings to libglassnt (#3224)
d6f6ceaba [build] Run Spotless formatter (NFC) (#3221)
0922f8af5 [commands] CommandScheduler.requiring(): Note return can be null (NFC) (#2934)
6812302ff [examples] Make DriveDistanceOffboard example work in sim (#3199)
f3f86b8e7 [wpimath] Add pose estimator overload for vision + std dev measurement (#3200)
1a2680b9e [wpilibj] Change CommandBase.withName() to return CommandBase (#3209)
435bbb6a8 [command] RamseteCommand: Output 0 if interrupted (#3216)
3cf44e0a5 [hal] Add function for changing HAL Notifier thread priority (#3218)
40b367513 [wpimath] Units.java: Add kg-lb conversions (#3203)
9f563d584 [glass] NT: Fix return value in StringToDoubleArray (#3208)
af4adf537 [glass] Auto-size plots to fit window (#3193)
2560146da [sim] GUI: Add option to show prefix in Other Devices (#3186)
eae3a6397 gitignore: Ignore .cache directory (#3196)
959611420 [wpilib] Require non-zero positive value for PIDController.period (#3175)
9522f2e8c [wpimath] Add methods to concatenate trajectories (#3139)
e42a0b6cf [wpimath] Rotation2d comment formatting (NFC) (#3162)
d1c7032de [wpimath] Fix order of setting gyro offset in pose estimators (#3176)
d241bc81a [sim] Add DoubleSolenoidSim and SolenoidSim classes (#3177)
cb7f39afa [wpilibc] Add RobotController::GetBatteryVoltage() to C++ (#3179)
99b5ad9eb [wpilibj] Fix warnings that are not unused variables or deprecation (#3161)
c14b23775 [build] Fixup doxygen generated include dirs to match what users would need (#3154)
d447c7dc3 [sim] Add SimDeviceSim ctor overloads (#3134)
247420c9c [build] Remove jcenter repo (#3157)
04b112e00 [build] Include debug info in plugin published artifacts (#3149)
be0ce9900 [examples] Use PWMSparkMax instead of PWMVictorSPX (#3156)
69e8d0b65 [wpilib] Move RomiGyro into main wpilibc/j (#3143)
94e685e1b [wpimath] Add custom residual support to EKF (#3148)
5899f3dd2 [sim] GUI: Make keyboard settings loading more robust (#3167)
f82aa1d56 [wpilib] Fix HolonomicDriveController atReference() behavior (#3163)
fe5c2cf4b [wpimath] Remove ControllerUtil.java (#3169)
43d40c6e9 [wpiutil] Suppress unchecked cast in CombinedRuntimeLoader (#3155)
3d44d8f79 [wpimath] Fix argument order in UKF docs (NFC) (#3147)
ba6fe8ff2 [cscore] Add USB camera change event (#3123)
533725888 [build] Tweak OpenCV cmake search paths to work better on Linux (#3144)
29bf9d6ef [cscore] Add polled support to listener
483beb636 [ntcore] Move CallbackManager to wpiutil
fdaec7759 [examples] Instantiate m_ramseteController in example (#3142)
8494a5761 Rename default branch to main (#3140)
45590eea2 [wpigui] Hardcode window scale to 1 on macOS (#3135)
834a64920 [build] Publish libglass and libglassnt to Maven (#3127)
2c2ccb361 [wpimath] Fix Rotation2d equality operator (#3128)
fb5c8c39a [wpigui] clang-tidy: readability-braces-around-statements
f7d39193a [wpigui] Fix copyright in pfd and wpigui_metal.mm
aec796b21 [ntcore] Fix conditional jump on uninitialized value (#3125)
fb13bb239 [sim] GUI: Add right click popup for keyboard joystick settings (#3119)
c517ec677 [build] Update thirdparty-imgui to 1.79-2 (#3118)
e8cbf2a71 [wpimath] Fix typo in SwerveDrivePoseEstimator doc (NFC) (#3112)
e9c86df46 [wpimath] Add tests for swerve module optimization (#3100)
6ba8c289c [examples] Remove negative of ArcadeDrive(fwd, ..) in the C++ Getting Started Example (#3102)
3f1672e89 [hal] Add SimDevice createInt() and createLong() (#3110)
15be5cbf1 [examples] Fix segfault in GearsBot C++ example (#3111)
4cf0e5e6d Add quick links to API documentation in README (#3082)
6b1898f12 Fix RT priority docs (NFC) (#3098)
b3426e9c0 [wpimath] Fix missing whitespace in pose estimator doc (#3097)
38c1a1f3e [examples] Fix feildRelative -> fieldRelative typo in XControllerCommand examples (#3104)
4488e25f1 [glass] Shorten SmartDashboard window names (#3096)
cfdb3058e [wpilibj] Update SimDeviceSimTest (#3095)
64adff5fe [examples] Fix typo in ArcadeDrive constructor parameter name (#3092)
6efc58e3d [build] Fix issues with build on windows, deprecations, and native utils (#3090)
f393989a5 [wpimath, wpiutil] Add wpi::array for compile time size checking (#3087)
d6ed20c1e [build] Set macOS deployment target to 10.14 (#3088)
7c524014c [hal] Add [[nodiscard]] to HAL_WaitForNotifierAlarm() (#3085)
406d055f0 [wpilib] Fixup wouldHitLowerLimit in elevator and arm simulation classes. (#3076)
04a90b5dd [examples] Don't continually set setpoint in PotentiometerPID Examples (#3084)
8c5bfa013 [sim] GUI: Add max value setting for keyboard joysticks (#3083)
bc80c5535 [hal] Add SimValue reset() function (#3064)
9c3b51ca0 [wpilib] Document simulation APIs (#3079)
26584ff14 [wpimath] Add model description to LinearSystemId Javadocs (#3080)
42c3d5286 [examples] Sync Java and C++ trajectories in sim example (#3081)
64e72f710 [wpilibc] Add missing function RoboRioSim::ResetData (#3073)
e95503798 [wpimath] Add optimize() to SwerveModuleState (#3065)
fb99910c2 [hal] Add SimInt and SimLong wrappers for int/long SimValue (#3066)
e620bd4d3 [doc] Add machine-readable websocket specification (#3059)
a44e761d9 [glass] Add support for plot Y axis labels
ea1974d57 [wpigui] Update imgui and implot to latest
85a0bd43c [wpimath] Add RKF45 integration (#3047)
278e0f126 [glass] Use .controllable to set widgets' read-only state (#3035)
d8652cfd4 [wpimath] Make Java DCMotor API consistent with C++ and fix motor calcs (#3046)
377b7065a [build] Add toggleOffOn to Java spotless (#3053)
1e9c79c58 [sim] Use plant output to retrieve simulated position (#3043)
78147aa34 [sim] GUI: Fix Keyboard Joystick (#3052)
cd4a2265b [ntcore] Fix NetworkTableEntry::GetRaw() (#3051)
767ac1de1 [build] Use deploy key for doc publish (#3048)
d762215d1 [build] Add publish documentation script (#3040)
1fd09593c [examples] Add missing TestInit method to GettingStarted Example (#3039)
e45a0f6ce [examples] Add RomiGyro to the Romi Reference example (#3037)
94f852572 Update imaging link and fix typo (#3038)
d73cf64e5 [examples] Update RomiReference to match motor directions (#3036)
f945462ba Bump copyright year to 2021 (#3033)
b05946175 [wpimath] Catch Drake JNI exceptions and rethrow them (#3032)
62f0f8190 [wpimath] Deduplicate angle modulus functions (#2998)
bf8c0da4b [glass] Add "About" popup with version number (#3031)
dfdd6b389 [build] Increase Gradle heap size in Gazebo build (#3028)
f5e0fc3e9 Finish clang-tidy cleanups (#3003)
d741101fe [sim] Revert accidental commit of WSProvider_PDP.h (#3027)
e1620799c [examples] Add C++ RomiReference example (#2969)
749c7adb1 [command] Fix use-after-free in CommandScheduler (#3024)
921a73391 [sim] Add WS providers for AddressableLED, PCM, and Solenoid (#3026)
26d0004fe [build] Split Actions into different yml files (#3025)
948af6d5b [wpilib] PWMSpeedController.get(): Apply Inversion (#3016)
670a187a3 [wpilibc] SuppliedValueWidget.h: Forward declare ShuffleboardContainer (#3021)
be9f72502 [ntcore] NetworkTableValue: Use std::forward instead of std::move (#3022)
daf3f4cb1 [cscore] cscore_raw_cv.h: Fix error in PutFrame() (#3019)
5acda4cc7 [wpimath] ElevatorFeedforward.h: Add time.h include
8452af606 [wpimath] units/radiation.h: Add mass.h include
630d44952 [hal] ErrorsInternal.h: Add stdint.h include
7372cf7d9 [cscore] Windows NetworkUtil.cpp: Add missing include
b7e46c558 Include .h from .inc/.inl files (NFC) (#3017)
bf8f8710e [examples] Update Romi template and example (#2996)
6ffe5b775 [glass] Ensure NetworkTableTree parent context menu has an id (#3015)
be0805b85 [build] Update to WPILibVersioningPlugin 4.1.0 (#3014)
65b2359b2 [build] Add spotless for other files (#3007)
8651aa73e [examples] Enable NT Flush in Field2d examples (#3013)
78b542737 [build] Add Gazebo build to Actions CI (#3004)
fccf86532 [sim] DriverStationGui: Fix two bugs (#3010)
185741760 [sim] WSProvider_Joystick: Fix off-by-1 in incoming buttons (#3011)
ee7114a58 [glass] Add drive class widgets (#2975)
00fa91d0d [glass] Use ImGui style for gyro widget colors (#3009)
b7a25bfc3 ThirdPartyNotices: Add portable file dialogs license (#3005)
a2e46b9a1 [glass] modernize-use-nullptr (NFC) (#3006)
a751fa22d [build] Apply spotless for java formatting (#1768)
e563a0b7d [wpimath] Make LinearSystemLoop move-constructible and move-assignable (#2967)
49085ca94 [glass] Add context menus to remove and add NetworkTables values (#2979)
560a850a2 [glass] Add NetworkTables Log window (#2997)
66782e231 [sim] Create Left/Right drivetrain current accessors (#3001)
b60eb1544 clang-tidy: bugprone-virtual-near-miss
cbe59fa3b clang-tidy: google-explicit-constructor
c97c6dc06 clang-tidy: google-readability-casting (NFC)
32fa97d68 clang-tidy: modernize-use-nullptr (NFC)
aee460326 clang-tidy: modernize-pass-by-value
29c7da5f1 clang-tidy: modernize-make-unique
6131f4e32 clang-tidy: modernize-concat-nested-namespaces (NFC)
67e03e625 clang-tidy: modernize-use-equals-default
b124f9101 clang-tidy: modernize-use-default-member-init
d11a3a638 clang-tidy: modernize-use-override (NFC)
4cc0706b0 clang-tidy: modernize-use-using (NFC)
885f5a978 [wpilibc] Speed up ScopedTracerTest (#2999)
60b596457 [wpilibj] Fix typos (NFC) (#3000)
6e1919414 [build] Bring naming checkstyle rules up to date with Google Style guide (#1781)
8c8ec5e63 [wpilibj] Suppress unchecked cast warnings (#2995)
b8413ddd5 [wpiutil] Add noexcept to timestamp static functions (#2994)
5d976b6e1 [glass] Load NetworkTableView settings on first draw (#2993)
2b4317452 Replace NOLINT(runtime/explicit) comments with NOLINT (NFC) (#2992)
1c3011ba4 [glass] Fix handling of "/" NetworkTables key (#2991)
574a42f3b [hal] Fix UnsafeManipulateDIO status check (#2987)
9005cd59e [wpilib] Clamp input voltage in sim classes (#2955)
dd494d4ab [glass] NetworkTablesModel::Update(): Avoid use-after-move (#2988)
7cca469a1 [wpimath] NormalizeAngle: Make inline, remove unnamed namespace (#2986)
2aed432b4 Add braces to C++ single-line loops and conditionals (NFC) (#2973)
0291a3ff5 [wpiutil] StringRef: Add noexcept to several constructors (#2984)
5d7315280 [wpimath] Update UnitsTest.cpp copyright (#2985)
254931b9a [wpimath] Remove LinearSystem from LinearSystemLoop (#2968)
aa89744c9 Update OtherVersions.md to include wpimath info (#2983)
1cda3f5ad [glass] Fix styleguide (#2976)
8f1f64ffb Remove year from file copyright message (NFC) (#2972)
2bc0a7795 [examples] Fix wpiformat warning about utility include (#2971)
4204da6ad [glass] Add application icon
7ac39b10f [wpigui] Add icon support
6b567e006 [wpimath] Add support for varying vision standard deviations in pose estimators (#2956)
df299d6ed [wpimath] Add UnscentedKalmanFilter::Correct() overload (#2966)
4e34f0523 [examples] Use ADXRS450_GyroSim class in simulation example (#2964)
9962f6fd7 [wpilib] Give Field2d a default Sendable name (#2953)
f9d492f4b [sim] GUI: Show "Other Devices" window by default (#2961)
a8bb2ef1c [sim] Fix ADXRS450_GyroSim and DutyCycleEncoderSim (#2963)
240c629cd [sim] Try to guess "Map Gamepad" setting (#2960)
952567dd3 [wpilibc] Add missing move constructors and assignment operators (#2959)
10b396b4c [sim] Various WebSockets fixes and enhancements (#2952)
699bbe21a [examples] Fix comments in Gearsbot to match implementation (NFC) (#2957)
27b67deca [glass] Add more widgets (#2947)
581b7ec55 [wpilib] Add option to flush NetworkTables every iterative loop
acfbb1a44 [ntcore] DispatcherBase::Flush: Use wpi::Now()
d85a6d8fe [ntcore] Reduce limit on flush and update rate to 5 ms
20fbb5c63 [sim] Fix stringop truncation warning from GCC 10 (#2945)
1051a06a7 [glass] Show NT timestamps in seconds (#2944)
98dfc2620 [glass] Fix plots (#2943)
1ba0a2ced [sim] GUI: Add keyboard virtual joystick support (#2940)
4afb13f98 [examples] Replace M_PI with wpi::math::pi (#2938)
b27d33675 [examples] Enhance Romi templates (#2931)
00b9ae77f [sim] Change default WS port number to 3300 (#2932)
65219f309 [examples] Update Field2d position in periodic() (#2928)
f78d1d434 [sim] Process WS Encoder reset internally (#2927)
941edca59 [hal] Add Java SimDeviceDataJNI.getSimDeviceName (#2924)
a699435ed [wpilibj] Fix FlywheelSim argument order in constructor (#2922)
66d641718 [examples] Add tasks to run Java examples (#2920)
558e37c41 [examples] Add simple differential drive simulation example (#2918)
4f40d991e [glass] Switch name of Glass back to glass (#2919)
549af9900 [build] Update native-utils to 2021.0.6 (#2914)
b33693009 [glass] Change basename of glass to Glass (#2915)
c9a0edfb8 [glass] Package macOS application bundle
2c5668af4 [wpigui] Add platform-specific preferences save
751dea32a [wpilibc] Try to work around ABI break introduced in #2901 (#2917)
cd8f4bfb1 [build] Package up msvc runtime into maven artifact (#2913)
a6cfcc686 [wpilibc] Move SendableChooser Doxygen comments to header (NFC) (#2911)
b8c4f603d [wpimath] Upgrade to Eigen 3.3.9 (#2910)
0075e4b39 [wpilibj] Fix NPE in Field2d (#2909)
125af556c [simulation] Fix halsim_gui ntcore and wpiutil deps (#2908)
963ad5c25 [wpilib] Add noise to Differential Drive simulator (#2903)
387f56cb7 [examples] Add Romi reference Java example and templates (#2905)
b3deda38c [examples] Zero motors on disabledInit() in sim physics examples (#2906)
2a5ca7745 [glass] Add glass: an application for display of robot data
727940d84 [wpilib] Move Field2d to SmartDashboard
8cd42478e [wpilib] SendableBuilder: Make GetTable() visible
c11d34b26 [command] Use addCommands in command group templates (#2900)
339d7445b [sim] Add HAL hooks for simulationPeriodic (#2881)
d16f05f2c [wpilib] Fix SmartDashboard update order (#2896)
5427b32a4 [wpiutil] unique_function: Restrict implicit conversion (#2899)
f73701239 [ntcore] Add missing SetDefault initializer_list functions (#2898)
f5a6fc070 [sim] Add initialized flag for all solenoids on a PCM (#2897)
bdf5ba91a [wpilibj] Fix typo in ElevatorSim (#2895)
bc8f33877 [wpilib] Add pose estimators (#2867)
3413bfc06 [wpilib] PIDController: Recompute the error in AtSetpoint() (#2822)
2056f0ce0 [wpilib] Fix bugs in Hatchbot examples (#2893)
5eb8cfd69 [wpilibc] Fix MatchDataSender (#2892)
e6a425448 [build] Delete test folders after tests execute (#2891)
d478ad00d [imgui] Allow usage of imgui_stdlib (#2889)
53eda861d [build] Add unit-testing infrastructure to examples (#2863)
cc1d86ba6 [sim] Add title to simulator GUI window (#2888)
f0528f00e [build] CMake: Use project-specific binary and source dirs (#2886)
5cd2ad124 [wpilibc] Add Color::operator!= (#2887)
6c00e7a90 [build] CI CMake: build with GUI enabled (#2884)
53170bbb5 Update roboRIO toolchain installation instructions (#2883)
467258e05 [sim] GUI: Add option to not zero disconnected joysticks (#2876)
129be23c9 Clarify JDK installation instructions in readme (#2882)
8e9290e86 [build] Add separate CMake setting for wpimath (#2885)
7cf5bebf8 [wpilibj] Cache NT writes from DriverStation (#2780)
f7f9087fb [command] Fix timing issue in RamseteCommand (#2871)
256e7904f [wpilibj] SimDeviceSim: Fix sim value changed callback (#2880)
c8ea1b6c3 [wpilib] Add function to adjust LQR controller gain for pure time delay (#2878)
2816b06c0 [sim] HAL_GetControlWord: Fully zero output (#2873)
4c695ea08 Add toolchain installation instructions to README (#2875)
a14d51806 [wpimath] DCMotor: fix doc typo (NFC) (#2868)
017097791 [build] CMake: build sim extensions as shared libs (#2866)
f61726b5a [build] Fix cmake-config files (#2865)
fc27fdac5 [wpilibc] Cache NT values from driver station (#2768)
47c59859e [sim] Make SimDevice callbacks synchronous (#2861)
6e76ab9c0 [build] Turn on WITH_GUI for Windows cmake CI
5f78b7670 [build] Set GLFW_INSTALL to OFF
5e0808c84 [wpigui] Fix Windows cmake build
508f05a47 [imgui] Fix typo in Windows CMake target sources
Change-Id: I1737b45965f31803a96676bedc7dc40e337aa321
git-subtree-dir: third_party/allwpilib
git-subtree-split: e473a00f9785f9949e5ced30901baeaf426d2fc9
Signed-off-by: Austin Schuh <austin.linux@gmail.com>
diff --git a/wpiutil/src/test/native/ManagedStaticTest.cpp b/wpiutil/src/test/native/ManagedStaticTest.cpp
index 81a4b9c..ab54499 100644
--- a/wpiutil/src/test/native/ManagedStaticTest.cpp
+++ b/wpiutil/src/test/native/ManagedStaticTest.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "wpi/ManagedStatic.h" // NOLINT(build/include_order)
@@ -23,6 +20,7 @@
{
refCount = 0;
wpi::ManagedStatic<StaticTestClass> managedStatic;
+ (void)managedStatic;
ASSERT_EQ(refCount, 0);
}
ASSERT_EQ(refCount, 0);
@@ -46,7 +44,7 @@
{
refCount = 0;
StaticTestClass* test = new StaticTestClass{};
- ASSERT_EQ(refCount, 1);
+ ASSERT_EQ(refCount, 1); // NOLINT
wpi::ManagedStatic<StaticTestClass> managedStatic(
test, [](void* val) { delete static_cast<StaticTestClass*>(val); });
ASSERT_EQ(refCount, 1);
diff --git a/wpiutil/src/test/native/cpp/Base64Test.cpp b/wpiutil/src/test/native/cpp/Base64Test.cpp
index caa35aa..542858d 100644
--- a/wpiutil/src/test/native/cpp/Base64Test.cpp
+++ b/wpiutil/src/test/native/cpp/Base64Test.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2015-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "gtest/gtest.h"
#include "wpi/Base64.h"
@@ -26,11 +23,12 @@
class Base64Test : public ::testing::TestWithParam<Base64TestParam> {
protected:
- StringRef GetPlain() {
- if (GetParam().plain_len < 0)
- return StringRef(GetParam().plain);
- else
- return StringRef(GetParam().plain, GetParam().plain_len);
+ std::string_view GetPlain() {
+ if (GetParam().plain_len < 0) {
+ return GetParam().plain;
+ } else {
+ return std::string_view(GetParam().plain, GetParam().plain_len);
+ }
}
};
@@ -53,7 +51,7 @@
TEST_P(Base64Test, DecodeStdString) {
std::string s;
- StringRef encoded = GetParam().encoded;
+ std::string_view encoded = GetParam().encoded;
EXPECT_EQ(encoded.size(), Base64Decode(encoded, &s));
ASSERT_EQ(GetPlain(), s);
@@ -64,9 +62,9 @@
TEST_P(Base64Test, DecodeSmallString) {
SmallString<128> buf;
- StringRef encoded = GetParam().encoded;
+ std::string_view encoded = GetParam().encoded;
size_t len;
- StringRef plain = Base64Decode(encoded, &len, buf);
+ std::string_view plain = Base64Decode(encoded, &len, buf);
EXPECT_EQ(encoded.size(), len);
ASSERT_EQ(GetPlain(), plain);
@@ -85,7 +83,8 @@
"mQgc28gb24uLi4K"},
};
-INSTANTIATE_TEST_SUITE_P(Base64Sample, Base64Test, ::testing::ValuesIn(sample));
+INSTANTIATE_TEST_SUITE_P(Base64SampleTests, Base64Test,
+ ::testing::ValuesIn(sample));
static Base64TestParam standard[] = {
{0, "", ""},
@@ -98,7 +97,7 @@
{2, "\xff\xef", "/+8="},
};
-INSTANTIATE_TEST_SUITE_P(Base64Standard, Base64Test,
+INSTANTIATE_TEST_SUITE_P(Base64StandardTests, Base64Test,
::testing::ValuesIn(standard));
} // namespace wpi
diff --git a/wpiutil/src/test/native/cpp/CircularBufferTest.cpp b/wpiutil/src/test/native/cpp/CircularBufferTest.cpp
index 7fe9e03..ad2285e 100644
--- a/wpiutil/src/test/native/cpp/CircularBufferTest.cpp
+++ b/wpiutil/src/test/native/cpp/CircularBufferTest.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2015-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "wpi/circular_buffer.h" // NOLINT(build/include_order)
@@ -21,31 +18,55 @@
static const std::array<double, 8> pushBackOut = {
{342.657, 234.252, 716.126, 132.344, 445.697, 22.727, 421.125, 799.913}};
-TEST(CircularBufferTest, PushFrontTest) {
+TEST(CircularBufferTest, PushFront) {
wpi::circular_buffer<double> queue(8);
for (auto& value : values) {
queue.push_front(value);
}
- for (size_t i = 0; i < pushFrontOut.size(); i++) {
+ for (size_t i = 0; i < pushFrontOut.size(); ++i) {
EXPECT_EQ(pushFrontOut[i], queue[i]);
}
}
-TEST(CircularBufferTest, PushBackTest) {
+TEST(CircularBufferTest, PushBack) {
wpi::circular_buffer<double> queue(8);
for (auto& value : values) {
queue.push_back(value);
}
- for (size_t i = 0; i < pushBackOut.size(); i++) {
+ for (size_t i = 0; i < pushBackOut.size(); ++i) {
EXPECT_EQ(pushBackOut[i], queue[i]);
}
}
-TEST(CircularBufferTest, PushPopTest) {
+TEST(CircularBufferTest, EmplaceFront) {
+ wpi::circular_buffer<double> queue(8);
+
+ for (auto& value : values) {
+ queue.emplace_front(value);
+ }
+
+ for (size_t i = 0; i < pushFrontOut.size(); ++i) {
+ EXPECT_EQ(pushFrontOut[i], queue[i]);
+ }
+}
+
+TEST(CircularBufferTest, EmplaceBack) {
+ wpi::circular_buffer<double> queue(8);
+
+ for (auto& value : values) {
+ queue.emplace_back(value);
+ }
+
+ for (size_t i = 0; i < pushBackOut.size(); ++i) {
+ EXPECT_EQ(pushBackOut[i], queue[i]);
+ }
+}
+
+TEST(CircularBufferTest, PushPop) {
wpi::circular_buffer<double> queue(3);
// Insert three elements into the buffer
@@ -88,21 +109,19 @@
EXPECT_EQ(4.0, queue[0]);
}
-TEST(CircularBufferTest, ResetTest) {
+TEST(CircularBufferTest, Reset) {
wpi::circular_buffer<double> queue(5);
- for (size_t i = 1; i < 6; i++) {
+ for (size_t i = 1; i < 6; ++i) {
queue.push_back(i);
}
queue.reset();
- for (size_t i = 0; i < 5; i++) {
- EXPECT_EQ(0.0, queue[i]);
- }
+ EXPECT_EQ(queue.size(), size_t{0});
}
-TEST(CircularBufferTest, ResizeTest) {
+TEST(CircularBufferTest, Resize) {
wpi::circular_buffer<double> queue(5);
/* Buffer contains {1, 2, 3, _, _}
@@ -207,3 +226,29 @@
EXPECT_EQ(2.0, queue[2]);
EXPECT_EQ(3.0, queue[3]);
}
+
+TEST(CircularBufferTest, Iterator) {
+ wpi::circular_buffer<double> queue(3);
+
+ queue.push_back(1.0);
+ queue.push_back(2.0);
+ queue.push_back(3.0);
+ queue.push_back(4.0); // Overwrite 1 with 4
+
+ // The buffer now contains 2, 3 and 4
+ const std::array<double, 3> values = {2.0, 3.0, 4.0};
+
+ // iterator
+ int i = 0;
+ for (auto& elem : queue) {
+ EXPECT_EQ(values[i], elem);
+ ++i;
+ }
+
+ // const_iterator
+ i = 0;
+ for (const auto& elem : queue) {
+ EXPECT_EQ(values[i], elem);
+ ++i;
+ }
+}
diff --git a/wpiutil/src/test/native/cpp/HttpParserTest.cpp b/wpiutil/src/test/native/cpp/HttpParserTest.cpp
index 8de2bc6..281abd0 100644
--- a/wpiutil/src/test/native/cpp/HttpParserTest.cpp
+++ b/wpiutil/src/test/native/cpp/HttpParserTest.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "wpi/HttpParser.h" // NOLINT(build/include_order)
@@ -14,7 +11,7 @@
TEST(HttpParserTest, UrlMethodHeadersComplete) {
HttpParser p{HttpParser::kRequest};
int callbacks = 0;
- p.url.connect([&](StringRef path) {
+ p.url.connect([&](std::string_view path) {
ASSERT_EQ(path, "/foo/bar");
ASSERT_EQ(p.GetUrl(), "/foo/bar");
++callbacks;
@@ -32,7 +29,7 @@
TEST(HttpParserTest, UrlMethodHeader) {
HttpParser p{HttpParser::kRequest};
int callbacks = 0;
- p.url.connect([&](StringRef path) {
+ p.url.connect([&](std::string_view path) {
ASSERT_EQ(path, "/foo/bar");
ASSERT_EQ(p.GetUrl(), "/foo/bar");
++callbacks;
@@ -52,7 +49,7 @@
TEST(HttpParserTest, StatusHeadersComplete) {
HttpParser p{HttpParser::kResponse};
int callbacks = 0;
- p.status.connect([&](StringRef status) {
+ p.status.connect([&](std::string_view status) {
ASSERT_EQ(status, "OK");
ASSERT_EQ(p.GetStatusCode(), 200u);
++callbacks;
@@ -69,7 +66,7 @@
TEST(HttpParserTest, StatusHeader) {
HttpParser p{HttpParser::kResponse};
int callbacks = 0;
- p.status.connect([&](StringRef status) {
+ p.status.connect([&](std::string_view status) {
ASSERT_EQ(status, "OK");
ASSERT_EQ(p.GetStatusCode(), 200u);
++callbacks;
@@ -86,7 +83,7 @@
TEST(HttpParserTest, HeaderFieldComplete) {
HttpParser p{HttpParser::kRequest};
int callbacks = 0;
- p.header.connect([&](StringRef name, StringRef value) {
+ p.header.connect([&](std::string_view name, std::string_view value) {
ASSERT_EQ(name, "Foo");
ASSERT_EQ(value, "Bar");
++callbacks;
@@ -109,7 +106,7 @@
TEST(HttpParserTest, HeaderFieldNext) {
HttpParser p{HttpParser::kRequest};
int callbacks = 0;
- p.header.connect([&](StringRef name, StringRef value) {
+ p.header.connect([&](std::string_view name, std::string_view value) {
ASSERT_EQ(name, "Foo");
ASSERT_EQ(value, "Bar");
++callbacks;
diff --git a/wpiutil/src/test/native/cpp/HttpUtilTest.cpp b/wpiutil/src/test/native/cpp/HttpUtilTest.cpp
index a83214d..524086a 100644
--- a/wpiutil/src/test/native/cpp/HttpUtilTest.cpp
+++ b/wpiutil/src/test/native/cpp/HttpUtilTest.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "wpi/HttpUtil.h" // NOLINT(build/include_order)
diff --git a/wpiutil/src/test/native/cpp/HttpWebSocketServerConnectionTest.cpp b/wpiutil/src/test/native/cpp/HttpWebSocketServerConnectionTest.cpp
index 8022cae..18a21be 100644
--- a/wpiutil/src/test/native/cpp/HttpWebSocketServerConnectionTest.cpp
+++ b/wpiutil/src/test/native/cpp/HttpWebSocketServerConnectionTest.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "wpi/HttpWebSocketServerConnection.h" // NOLINT(build/include_order)
@@ -15,7 +12,7 @@
: public HttpWebSocketServerConnection<HttpWebSocketServerConnectionTest> {
public:
HttpWebSocketServerConnectionTest(std::shared_ptr<uv::Stream> stream,
- ArrayRef<StringRef> protocols)
+ span<const std::string_view> protocols)
: HttpWebSocketServerConnection{stream, protocols} {}
void ProcessRequest() override { ++gotRequest; }
diff --git a/wpiutil/src/test/native/cpp/StaticCircularBufferTest.cpp b/wpiutil/src/test/native/cpp/StaticCircularBufferTest.cpp
index 72da38b..f95f9cb 100644
--- a/wpiutil/src/test/native/cpp/StaticCircularBufferTest.cpp
+++ b/wpiutil/src/test/native/cpp/StaticCircularBufferTest.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "wpi/static_circular_buffer.h" // NOLINT(build/include_order)
@@ -21,7 +18,7 @@
static const std::array<double, 8> pushBackOut = {
{342.657, 234.252, 716.126, 132.344, 445.697, 22.727, 421.125, 799.913}};
-TEST(StaticCircularBufferTest, PushFrontTest) {
+TEST(StaticCircularBufferTest, PushFront) {
wpi::static_circular_buffer<double, 8> queue;
for (auto& value : values) {
@@ -33,7 +30,7 @@
}
}
-TEST(StaticCircularBufferTest, PushBackTest) {
+TEST(StaticCircularBufferTest, PushBack) {
wpi::static_circular_buffer<double, 8> queue;
for (auto& value : values) {
@@ -45,7 +42,7 @@
}
}
-TEST(StaticCircularBufferTest, EmplaceFrontTest) {
+TEST(StaticCircularBufferTest, EmplaceFront) {
wpi::static_circular_buffer<double, 8> queue;
for (auto& value : values) {
@@ -57,7 +54,7 @@
}
}
-TEST(StaticCircularBufferTest, EmplaceBackTest) {
+TEST(StaticCircularBufferTest, EmplaceBack) {
wpi::static_circular_buffer<double, 8> queue;
for (auto& value : values) {
@@ -69,7 +66,7 @@
}
}
-TEST(StaticCircularBufferTest, PushPopTest) {
+TEST(StaticCircularBufferTest, PushPop) {
wpi::static_circular_buffer<double, 3> queue;
// Insert three elements into the buffer
@@ -112,7 +109,7 @@
EXPECT_EQ(4.0, queue[0]);
}
-TEST(StaticCircularBufferTest, ResetTest) {
+TEST(StaticCircularBufferTest, Reset) {
wpi::static_circular_buffer<double, 5> queue;
for (size_t i = 1; i < 6; ++i) {
@@ -124,7 +121,7 @@
EXPECT_EQ(queue.size(), size_t{0});
}
-TEST(StaticCircularBufferTest, IteratorTest) {
+TEST(StaticCircularBufferTest, Iterator) {
wpi::static_circular_buffer<double, 3> queue;
queue.push_back(1.0);
diff --git a/wpiutil/src/test/native/cpp/SynchronizationTest.cpp b/wpiutil/src/test/native/cpp/SynchronizationTest.cpp
new file mode 100644
index 0000000..a349c54
--- /dev/null
+++ b/wpiutil/src/test/native/cpp/SynchronizationTest.cpp
@@ -0,0 +1,56 @@
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
+
+#include "wpi/Synchronization.h" // NOLINT(build/include_order)
+
+#include <thread>
+
+#include "gtest/gtest.h"
+
+TEST(EventTest, AutoReset) {
+ auto event = wpi::CreateEvent(false, false);
+ std::thread thr([&] { wpi::SetEvent(event); });
+ wpi::WaitForObject(event);
+ thr.join();
+ bool timedOut;
+ wpi::WaitForObject(event, 0, &timedOut);
+ ASSERT_EQ(timedOut, true);
+}
+
+TEST(EventTest, ManualReset) {
+ auto event = wpi::CreateEvent(true, false);
+ int done = 0;
+ std::thread thr([&] {
+ wpi::SetEvent(event);
+ ++done;
+ });
+ wpi::WaitForObject(event);
+ thr.join();
+ ASSERT_EQ(done, 1);
+ bool timedOut;
+ wpi::WaitForObject(event, 0, &timedOut);
+ ASSERT_EQ(timedOut, false);
+}
+
+TEST(EventTest, InitialSet) {
+ auto event = wpi::CreateEvent(false, true);
+ bool timedOut;
+ wpi::WaitForObject(event, 0, &timedOut);
+ ASSERT_EQ(timedOut, false);
+}
+
+TEST(EventTest, WaitMultiple) {
+ auto event1 = wpi::CreateEvent(false, false);
+ auto event2 = wpi::CreateEvent(false, false);
+ std::thread thr([&] { wpi::SetEvent(event2); });
+ WPI_Handle signaled[2];
+ auto result1 = wpi::WaitForObjects({event1, event2}, signaled);
+ thr.join();
+ ASSERT_EQ(result1.size(), 1u);
+ ASSERT_EQ(result1[0], event2);
+ bool timedOut;
+ auto result2 = wpi::WaitForObjects({event1, event2}, signaled, 0, &timedOut);
+ ASSERT_EQ(timedOut, true);
+ ASSERT_EQ(result2.size(), 0u);
+}
diff --git a/wpiutil/src/test/native/cpp/UidVectorTest.cpp b/wpiutil/src/test/native/cpp/UidVectorTest.cpp
index e11c7b2..f9e1624 100644
--- a/wpiutil/src/test/native/cpp/UidVectorTest.cpp
+++ b/wpiutil/src/test/native/cpp/UidVectorTest.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "wpi/UidVector.h" // NOLINT(build/include_order)
@@ -39,7 +36,9 @@
v.emplace_back(2);
v.emplace_back(1);
std::vector<int> out;
- for (auto&& val : v) out.push_back(val);
+ for (auto&& val : v) {
+ out.push_back(val);
+ }
ASSERT_EQ(out.size(), 2u);
EXPECT_EQ(out[0], 2);
EXPECT_EQ(out[1], 1);
diff --git a/wpiutil/src/test/native/cpp/WebSocketClientTest.cpp b/wpiutil/src/test/native/cpp/WebSocketClientTest.cpp
index 2db9b54..9d85e66 100644
--- a/wpiutil/src/test/native/cpp/WebSocketClientTest.cpp
+++ b/wpiutil/src/test/native/cpp/WebSocketClientTest.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "wpi/WebSocket.h" // NOLINT(build/include_order)
@@ -11,6 +8,7 @@
#include "wpi/Base64.h"
#include "wpi/HttpParser.h"
#include "wpi/SmallString.h"
+#include "wpi/StringExtras.h"
#include "wpi/raw_uv_ostream.h"
#include "wpi/sha1.h"
@@ -20,9 +18,11 @@
public:
WebSocketClientTest() {
// Bare bones server
- req.header.connect([this](StringRef name, StringRef value) {
+ req.header.connect([this](std::string_view name, std::string_view value) {
// save key (required for valid response)
- if (name.equals_lower("sec-websocket-key")) clientKey = value;
+ if (equals_lower(name, "sec-websocket-key")) {
+ clientKey = value;
+ }
});
req.headersComplete.connect([this](bool) {
// send response
@@ -36,37 +36,48 @@
SHA1 hash;
hash.Update(clientKey);
hash.Update("258EAFA5-E914-47DA-95CA-C5AB0DC85B11");
- if (mockBadAccept) hash.Update("1");
+ if (mockBadAccept) {
+ hash.Update("1");
+ }
SmallString<64> hashBuf;
SmallString<64> acceptBuf;
os << "Sec-WebSocket-Accept: "
<< Base64Encode(hash.RawFinal(hashBuf), acceptBuf) << "\r\n";
- if (!mockProtocol.empty())
+ if (!mockProtocol.empty()) {
os << "Sec-WebSocket-Protocol: " << mockProtocol << "\r\n";
+ }
os << "\r\n";
conn->Write(bufs, [](auto bufs, uv::Error) {
- for (auto& buf : bufs) buf.Deallocate();
+ for (auto& buf : bufs) {
+ buf.Deallocate();
+ }
});
serverHeadersDone = true;
- if (connected) connected();
+ if (connected) {
+ connected();
+ }
});
serverPipe->Listen([this] {
conn = serverPipe->Accept();
conn->StartRead();
conn->data.connect([this](uv::Buffer& buf, size_t size) {
- StringRef data{buf.base, size};
+ std::string_view data{buf.base, size};
if (!serverHeadersDone) {
data = req.Execute(data);
- if (req.HasError()) Finish();
+ if (req.HasError()) {
+ Finish();
+ }
ASSERT_EQ(req.GetError(), HPE_OK) << http_errno_name(req.GetError());
- if (data.empty()) return;
+ if (data.empty()) {
+ return;
+ }
}
- wireData.insert(wireData.end(), data.bytes_begin(), data.bytes_end());
+ wireData.insert(wireData.end(), data.begin(), data.end());
});
conn->end.connect([this] { Finish(); });
});
@@ -87,12 +98,13 @@
clientPipe->Connect(pipeName, [&] {
auto ws = WebSocket::CreateClient(*clientPipe, "/test", pipeName);
- ws->closed.connect([&](uint16_t code, StringRef reason) {
+ ws->closed.connect([&](uint16_t code, std::string_view reason) {
Finish();
- if (code != 1005 && code != 1006)
+ if (code != 1005 && code != 1006) {
FAIL() << "Code: " << code << " Reason: " << reason;
+ }
});
- ws->open.connect([&](StringRef protocol) {
+ ws->open.connect([&](std::string_view protocol) {
++gotOpen;
Finish();
ASSERT_TRUE(protocol.empty());
@@ -101,7 +113,9 @@
loop->Run();
- if (HasFatalFailure()) return;
+ if (HasFatalFailure()) {
+ return;
+ }
ASSERT_EQ(gotOpen, 1);
}
@@ -112,12 +126,12 @@
clientPipe->Connect(pipeName, [&] {
auto ws = WebSocket::CreateClient(*clientPipe, "/test", pipeName);
- ws->closed.connect([&](uint16_t code, StringRef msg) {
+ ws->closed.connect([&](uint16_t code, std::string_view msg) {
Finish();
++gotClosed;
ASSERT_EQ(code, 1002) << "Message: " << msg;
});
- ws->open.connect([&](StringRef protocol) {
+ ws->open.connect([&](std::string_view protocol) {
Finish();
FAIL() << "Got open";
});
@@ -125,7 +139,9 @@
loop->Run();
- if (HasFatalFailure()) return;
+ if (HasFatalFailure()) {
+ return;
+ }
ASSERT_EQ(gotClosed, 1);
}
@@ -137,12 +153,13 @@
clientPipe->Connect(pipeName, [&] {
auto ws = WebSocket::CreateClient(*clientPipe, "/test", pipeName,
{"myProtocol", "myProtocol2"});
- ws->closed.connect([&](uint16_t code, StringRef msg) {
+ ws->closed.connect([&](uint16_t code, std::string_view msg) {
Finish();
- if (code != 1005 && code != 1006)
+ if (code != 1005 && code != 1006) {
FAIL() << "Code: " << code << "Message: " << msg;
+ }
});
- ws->open.connect([&](StringRef protocol) {
+ ws->open.connect([&](std::string_view protocol) {
++gotOpen;
Finish();
ASSERT_EQ(protocol, "myProtocol");
@@ -151,7 +168,9 @@
loop->Run();
- if (HasFatalFailure()) return;
+ if (HasFatalFailure()) {
+ return;
+ }
ASSERT_EQ(gotOpen, 1);
}
@@ -162,12 +181,12 @@
clientPipe->Connect(pipeName, [&] {
auto ws = WebSocket::CreateClient(*clientPipe, "/test", pipeName);
- ws->closed.connect([&](uint16_t code, StringRef msg) {
+ ws->closed.connect([&](uint16_t code, std::string_view msg) {
Finish();
++gotClosed;
ASSERT_EQ(code, 1003) << "Message: " << msg;
});
- ws->open.connect([&](StringRef protocol) {
+ ws->open.connect([&](std::string_view protocol) {
Finish();
FAIL() << "Got open";
});
@@ -175,7 +194,9 @@
loop->Run();
- if (HasFatalFailure()) return;
+ if (HasFatalFailure()) {
+ return;
+ }
ASSERT_EQ(gotClosed, 1);
}
@@ -184,13 +205,13 @@
clientPipe->Connect(pipeName, [&] {
auto ws = WebSocket::CreateClient(*clientPipe, "/test", pipeName,
- StringRef{"myProtocol"});
- ws->closed.connect([&](uint16_t code, StringRef msg) {
+ {{"myProtocol"}});
+ ws->closed.connect([&](uint16_t code, std::string_view msg) {
Finish();
++gotClosed;
ASSERT_EQ(code, 1002) << "Message: " << msg;
});
- ws->open.connect([&](StringRef protocol) {
+ ws->open.connect([&](std::string_view protocol) {
Finish();
FAIL() << "Got open";
});
@@ -198,7 +219,9 @@
loop->Run();
- if (HasFatalFailure()) return;
+ if (HasFatalFailure()) {
+ return;
+ }
ASSERT_EQ(gotClosed, 1);
}
@@ -213,7 +236,9 @@
WebSocketClientDataTest() {
clientPipe->Connect(pipeName, [&] {
ws = WebSocket::CreateClient(*clientPipe, "/test", pipeName);
- if (setupWebSocket) setupWebSocket();
+ if (setupWebSocket) {
+ setupWebSocket();
+ }
});
}
@@ -228,8 +253,8 @@
int gotCallback = 0;
std::vector<uint8_t> data(GetParam(), 0x03u);
setupWebSocket = [&] {
- ws->open.connect([&](StringRef) {
- ws->SendBinary(uv::Buffer(data), [&](auto bufs, uv::Error) {
+ ws->open.connect([&](std::string_view) {
+ ws->SendBinary({{data}}, [&](auto bufs, uv::Error) {
++gotCallback;
ws->Terminate();
ASSERT_FALSE(bufs.empty());
@@ -250,7 +275,7 @@
int gotCallback = 0;
std::vector<uint8_t> data(GetParam(), 0x03u);
setupWebSocket = [&] {
- ws->binary.connect([&](ArrayRef<uint8_t> inData, bool fin) {
+ ws->binary.connect([&](auto inData, bool fin) {
++gotCallback;
ws->Terminate();
ASSERT_TRUE(fin);
@@ -259,9 +284,7 @@
});
};
auto message = BuildMessage(0x02, true, false, data);
- connected = [&] {
- conn->Write(uv::Buffer(message), [&](auto bufs, uv::Error) {});
- };
+ connected = [&] { conn->Write({{message}}, [&](auto bufs, uv::Error) {}); };
loop->Run();
@@ -276,19 +299,17 @@
int gotCallback = 0;
std::vector<uint8_t> data(GetParam(), ' ');
setupWebSocket = [&] {
- ws->text.connect([&](StringRef, bool) {
+ ws->text.connect([&](std::string_view, bool) {
ws->Terminate();
FAIL() << "Should not have gotten masked message";
});
- ws->closed.connect([&](uint16_t code, StringRef reason) {
+ ws->closed.connect([&](uint16_t code, std::string_view reason) {
++gotCallback;
ASSERT_EQ(code, 1002) << "reason: " << reason;
});
};
auto message = BuildMessage(0x01, true, true, data);
- connected = [&] {
- conn->Write(uv::Buffer(message), [&](auto bufs, uv::Error) {});
- };
+ connected = [&] { conn->Write({{message}}, [&](auto bufs, uv::Error) {}); };
loop->Run();
diff --git a/wpiutil/src/test/native/cpp/WebSocketIntegrationTest.cpp b/wpiutil/src/test/native/cpp/WebSocketIntegrationTest.cpp
index 9a66a2e..3de75d9 100644
--- a/wpiutil/src/test/native/cpp/WebSocketIntegrationTest.cpp
+++ b/wpiutil/src/test/native/cpp/WebSocketIntegrationTest.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "wpi/WebSocketServer.h" // NOLINT(build/include_order)
@@ -22,7 +19,7 @@
serverPipe->Listen([&]() {
auto conn = serverPipe->Accept();
auto server = WebSocketServer::Create(*conn);
- server->connected.connect([&](StringRef url, WebSocket&) {
+ server->connected.connect([&](std::string_view url, WebSocket&) {
++gotServerOpen;
ASSERT_EQ(url, "/test");
});
@@ -30,12 +27,13 @@
clientPipe->Connect(pipeName, [&] {
auto ws = WebSocket::CreateClient(*clientPipe, "/test", pipeName);
- ws->closed.connect([&](uint16_t code, StringRef reason) {
+ ws->closed.connect([&](uint16_t code, std::string_view reason) {
Finish();
- if (code != 1005 && code != 1006)
+ if (code != 1005 && code != 1006) {
FAIL() << "Code: " << code << " Reason: " << reason;
+ }
});
- ws->open.connect([&, s = ws.get()](StringRef) {
+ ws->open.connect([&, s = ws.get()](std::string_view) {
++gotClientOpen;
s->Close();
});
@@ -54,7 +52,7 @@
serverPipe->Listen([&]() {
auto conn = serverPipe->Accept();
auto server = WebSocketServer::Create(*conn, {"proto1", "proto2"});
- server->connected.connect([&](StringRef, WebSocket& ws) {
+ server->connected.connect([&](std::string_view, WebSocket& ws) {
++gotServerOpen;
ASSERT_EQ(ws.GetProtocol(), "proto1");
});
@@ -63,12 +61,13 @@
clientPipe->Connect(pipeName, [&] {
auto ws =
WebSocket::CreateClient(*clientPipe, "/test", pipeName, {"proto1"});
- ws->closed.connect([&](uint16_t code, StringRef reason) {
+ ws->closed.connect([&](uint16_t code, std::string_view reason) {
Finish();
- if (code != 1005 && code != 1006)
+ if (code != 1005 && code != 1006) {
FAIL() << "Code: " << code << " Reason: " << reason;
+ }
});
- ws->open.connect([&, s = ws.get()](StringRef protocol) {
+ ws->open.connect([&, s = ws.get()](std::string_view protocol) {
++gotClientOpen;
s->Close();
ASSERT_EQ(protocol, "proto1");
@@ -87,20 +86,21 @@
serverPipe->Listen([&]() {
auto conn = serverPipe->Accept();
auto server = WebSocketServer::Create(*conn);
- server->connected.connect([&](StringRef, WebSocket& ws) {
- ws.SendBinary(uv::Buffer{"\x03\x04", 2}, [&](auto, uv::Error) {});
+ server->connected.connect([&](std::string_view, WebSocket& ws) {
+ ws.SendBinary({uv::Buffer{"\x03\x04", 2}}, [&](auto, uv::Error) {});
ws.Close();
});
});
clientPipe->Connect(pipeName, [&] {
auto ws = WebSocket::CreateClient(*clientPipe, "/test", pipeName);
- ws->closed.connect([&](uint16_t code, StringRef reason) {
+ ws->closed.connect([&](uint16_t code, std::string_view reason) {
Finish();
- if (code != 1005 && code != 1006)
+ if (code != 1005 && code != 1006) {
FAIL() << "Code: " << code << " Reason: " << reason;
+ }
});
- ws->binary.connect([&](ArrayRef<uint8_t> data, bool) {
+ ws->binary.connect([&](auto data, bool) {
++gotData;
std::vector<uint8_t> recvData{data.begin(), data.end()};
std::vector<uint8_t> expectData{0x03, 0x04};
@@ -119,8 +119,8 @@
serverPipe->Listen([&]() {
auto conn = serverPipe->Accept();
auto server = WebSocketServer::Create(*conn);
- server->connected.connect([&](StringRef, WebSocket& ws) {
- ws.text.connect([&](StringRef data, bool) {
+ server->connected.connect([&](std::string_view, WebSocket& ws) {
+ ws.text.connect([&](std::string_view data, bool) {
++gotData;
ASSERT_EQ(data, "hello");
});
@@ -129,13 +129,14 @@
clientPipe->Connect(pipeName, [&] {
auto ws = WebSocket::CreateClient(*clientPipe, "/test", pipeName);
- ws->closed.connect([&](uint16_t code, StringRef reason) {
+ ws->closed.connect([&](uint16_t code, std::string_view reason) {
Finish();
- if (code != 1005 && code != 1006)
+ if (code != 1005 && code != 1006) {
FAIL() << "Code: " << code << " Reason: " << reason;
+ }
});
- ws->open.connect([&, s = ws.get()](StringRef) {
- s->SendText(uv::Buffer{"hello"}, [&](auto, uv::Error) {});
+ ws->open.connect([&, s = ws.get()](std::string_view) {
+ s->SendText({{"hello"}}, [&](auto, uv::Error) {});
s->Close();
});
});
diff --git a/wpiutil/src/test/native/cpp/WebSocketServerTest.cpp b/wpiutil/src/test/native/cpp/WebSocketServerTest.cpp
index d11fdda..83561bf 100644
--- a/wpiutil/src/test/native/cpp/WebSocketServerTest.cpp
+++ b/wpiutil/src/test/native/cpp/WebSocketServerTest.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "wpi/WebSocket.h" // NOLINT(build/include_order)
@@ -24,28 +21,36 @@
serverPipe->Listen([this]() {
auto conn = serverPipe->Accept();
ws = WebSocket::CreateServer(*conn, "foo", "13");
- if (setupWebSocket) setupWebSocket();
+ if (setupWebSocket) {
+ setupWebSocket();
+ }
});
clientPipe->Connect(pipeName, [this]() {
clientPipe->StartRead();
clientPipe->data.connect([this](uv::Buffer& buf, size_t size) {
- StringRef data{buf.base, size};
+ std::string_view data{buf.base, size};
if (!headersDone) {
data = resp.Execute(data);
- if (resp.HasError()) Finish();
+ if (resp.HasError()) {
+ Finish();
+ }
ASSERT_EQ(resp.GetError(), HPE_OK)
<< http_errno_name(resp.GetError());
- if (data.empty()) return;
+ if (data.empty()) {
+ return;
+ }
}
- wireData.insert(wireData.end(), data.bytes_begin(), data.bytes_end());
- if (handleData) handleData(data);
+ wireData.insert(wireData.end(), data.begin(), data.end());
+ if (handleData) {
+ handleData(data);
+ }
});
clientPipe->end.connect([this]() { Finish(); });
});
}
std::function<void()> setupWebSocket;
- std::function<void(StringRef)> handleData;
+ std::function<void(std::string_view)> handleData;
std::vector<uint8_t> wireData;
std::shared_ptr<WebSocket> ws;
HttpParser resp{HttpParser::kResponse};
@@ -59,8 +64,8 @@
TEST_F(WebSocketServerTest, Terminate) {
int gotClosed = 0;
setupWebSocket = [&] {
- ws->open.connect([&](StringRef) { ws->Terminate(); });
- ws->closed.connect([&](uint16_t code, StringRef reason) {
+ ws->open.connect([&](std::string_view) { ws->Terminate(); });
+ ws->closed.connect([&](uint16_t code, std::string_view reason) {
++gotClosed;
ASSERT_EQ(code, 1006) << "reason: " << reason;
});
@@ -75,8 +80,8 @@
TEST_F(WebSocketServerTest, TerminateCode) {
int gotClosed = 0;
setupWebSocket = [&] {
- ws->open.connect([&](StringRef) { ws->Terminate(1000); });
- ws->closed.connect([&](uint16_t code, StringRef reason) {
+ ws->open.connect([&](std::string_view) { ws->Terminate(1000); });
+ ws->closed.connect([&](uint16_t code, std::string_view reason) {
++gotClosed;
ASSERT_EQ(code, 1000) << "reason: " << reason;
});
@@ -91,8 +96,8 @@
TEST_F(WebSocketServerTest, TerminateReason) {
int gotClosed = 0;
setupWebSocket = [&] {
- ws->open.connect([&](StringRef) { ws->Terminate(1000, "reason"); });
- ws->closed.connect([&](uint16_t code, StringRef reason) {
+ ws->open.connect([&](std::string_view) { ws->Terminate(1000, "reason"); });
+ ws->closed.connect([&](uint16_t code, std::string_view reason) {
++gotClosed;
ASSERT_EQ(code, 1000);
ASSERT_EQ(reason, "reason");
@@ -112,16 +117,16 @@
TEST_F(WebSocketServerTest, CloseBasic) {
int gotClosed = 0;
setupWebSocket = [&] {
- ws->open.connect([&](StringRef) { ws->Close(); });
- ws->closed.connect([&](uint16_t code, StringRef reason) {
+ ws->open.connect([&](std::string_view) { ws->Close(); });
+ ws->closed.connect([&](uint16_t code, std::string_view reason) {
++gotClosed;
ASSERT_EQ(code, 1005) << "reason: " << reason;
});
};
// need to respond with close for server to finish shutdown
auto message = BuildMessage(0x08, true, true, {});
- handleData = [&](StringRef) {
- clientPipe->Write(uv::Buffer(message), [&](auto bufs, uv::Error) {});
+ handleData = [&](std::string_view) {
+ clientPipe->Write({{message}}, [&](auto bufs, uv::Error) {});
};
loop->Run();
@@ -134,8 +139,8 @@
TEST_F(WebSocketServerTest, CloseCode) {
int gotClosed = 0;
setupWebSocket = [&] {
- ws->open.connect([&](StringRef) { ws->Close(1000); });
- ws->closed.connect([&](uint16_t code, StringRef reason) {
+ ws->open.connect([&](std::string_view) { ws->Close(1000); });
+ ws->closed.connect([&](uint16_t code, std::string_view reason) {
++gotClosed;
ASSERT_EQ(code, 1000) << "reason: " << reason;
});
@@ -143,8 +148,8 @@
// need to respond with close for server to finish shutdown
const uint8_t contents[] = {0x03u, 0xe8u};
auto message = BuildMessage(0x08, true, true, contents);
- handleData = [&](StringRef) {
- clientPipe->Write(uv::Buffer(message), [&](auto bufs, uv::Error) {});
+ handleData = [&](std::string_view) {
+ clientPipe->Write({{message}}, [&](auto bufs, uv::Error) {});
};
loop->Run();
@@ -157,8 +162,8 @@
TEST_F(WebSocketServerTest, CloseReason) {
int gotClosed = 0;
setupWebSocket = [&] {
- ws->open.connect([&](StringRef) { ws->Close(1000, "hangup"); });
- ws->closed.connect([&](uint16_t code, StringRef reason) {
+ ws->open.connect([&](std::string_view) { ws->Close(1000, "hangup"); });
+ ws->closed.connect([&](uint16_t code, std::string_view reason) {
++gotClosed;
ASSERT_EQ(code, 1000);
ASSERT_EQ(reason, "hangup");
@@ -167,8 +172,8 @@
// need to respond with close for server to finish shutdown
const uint8_t contents[] = {0x03u, 0xe8u, 'h', 'a', 'n', 'g', 'u', 'p'};
auto message = BuildMessage(0x08, true, true, contents);
- handleData = [&](StringRef) {
- clientPipe->Write(uv::Buffer(message), [&](auto bufs, uv::Error) {});
+ handleData = [&](std::string_view) {
+ clientPipe->Write({{message}}, [&](auto bufs, uv::Error) {});
};
loop->Run();
@@ -185,14 +190,14 @@
TEST_F(WebSocketServerTest, ReceiveCloseBasic) {
int gotClosed = 0;
setupWebSocket = [&] {
- ws->closed.connect([&](uint16_t code, StringRef reason) {
+ ws->closed.connect([&](uint16_t code, std::string_view reason) {
++gotClosed;
ASSERT_EQ(code, 1005) << "reason: " << reason;
});
};
auto message = BuildMessage(0x08, true, true, {});
resp.headersComplete.connect([&](bool) {
- clientPipe->Write(uv::Buffer(message), [&](auto bufs, uv::Error) {});
+ clientPipe->Write({{message}}, [&](auto bufs, uv::Error) {});
});
loop->Run();
@@ -206,7 +211,7 @@
TEST_F(WebSocketServerTest, ReceiveCloseCode) {
int gotClosed = 0;
setupWebSocket = [&] {
- ws->closed.connect([&](uint16_t code, StringRef reason) {
+ ws->closed.connect([&](uint16_t code, std::string_view reason) {
++gotClosed;
ASSERT_EQ(code, 1000) << "reason: " << reason;
});
@@ -214,7 +219,7 @@
const uint8_t contents[] = {0x03u, 0xe8u};
auto message = BuildMessage(0x08, true, true, contents);
resp.headersComplete.connect([&](bool) {
- clientPipe->Write(uv::Buffer(message), [&](auto bufs, uv::Error) {});
+ clientPipe->Write({{message}}, [&](auto bufs, uv::Error) {});
});
loop->Run();
@@ -228,7 +233,7 @@
TEST_F(WebSocketServerTest, ReceiveCloseReason) {
int gotClosed = 0;
setupWebSocket = [&] {
- ws->closed.connect([&](uint16_t code, StringRef reason) {
+ ws->closed.connect([&](uint16_t code, std::string_view reason) {
++gotClosed;
ASSERT_EQ(code, 1000);
ASSERT_EQ(reason, "hangup");
@@ -237,7 +242,7 @@
const uint8_t contents[] = {0x03u, 0xe8u, 'h', 'a', 'n', 'g', 'u', 'p'};
auto message = BuildMessage(0x08, true, true, contents);
resp.headersComplete.connect([&](bool) {
- clientPipe->Write(uv::Buffer(message), [&](auto bufs, uv::Error) {});
+ clientPipe->Write({{message}}, [&](auto bufs, uv::Error) {});
});
loop->Run();
@@ -266,14 +271,14 @@
int gotCallback = 0;
std::vector<uint8_t> data(4, 0x03);
setupWebSocket = [&] {
- ws->closed.connect([&](uint16_t code, StringRef reason) {
+ ws->closed.connect([&](uint16_t code, std::string_view reason) {
++gotCallback;
ASSERT_EQ(code, 1002) << "reason: " << reason;
});
};
auto message = BuildMessage(GetParam(), true, true, data);
resp.headersComplete.connect([&](bool) {
- clientPipe->Write(uv::Buffer(message), [&](auto bufs, uv::Error) {});
+ clientPipe->Write({{message}}, [&](auto bufs, uv::Error) {});
});
loop->Run();
@@ -297,14 +302,14 @@
int gotCallback = 0;
std::vector<uint8_t> data(4, 0x03);
setupWebSocket = [&] {
- ws->closed.connect([&](uint16_t code, StringRef reason) {
+ ws->closed.connect([&](uint16_t code, std::string_view reason) {
++gotCallback;
ASSERT_EQ(code, 1002) << "reason: " << reason;
});
};
auto message = BuildMessage(GetParam(), false, true, data);
resp.headersComplete.connect([&](bool) {
- clientPipe->Write(uv::Buffer(message), [&](auto bufs, uv::Error) {});
+ clientPipe->Write({{message}}, [&](auto bufs, uv::Error) {});
});
loop->Run();
@@ -324,14 +329,14 @@
int gotCallback = 0;
std::vector<uint8_t> data(4, 0x03);
setupWebSocket = [&] {
- ws->closed.connect([&](uint16_t code, StringRef reason) {
+ ws->closed.connect([&](uint16_t code, std::string_view reason) {
++gotCallback;
ASSERT_EQ(code, 1002) << "reason: " << reason;
});
};
auto message = BuildMessage(0x00, false, true, data);
resp.headersComplete.connect([&](bool) {
- clientPipe->Write(uv::Buffer(message), [&](auto bufs, uv::Error) {});
+ clientPipe->Write({{message}}, [&](auto bufs, uv::Error) {});
});
loop->Run();
@@ -344,7 +349,7 @@
int gotCallback = 0;
std::vector<uint8_t> data(4, 0x03);
setupWebSocket = [&] {
- ws->closed.connect([&](uint16_t code, StringRef reason) {
+ ws->closed.connect([&](uint16_t code, std::string_view reason) {
++gotCallback;
ASSERT_EQ(code, 1002) << "reason: " << reason;
});
@@ -352,8 +357,7 @@
auto message = BuildMessage(0x01, true, true, {}); // FIN=1
auto message2 = BuildMessage(0x00, false, true, data);
resp.headersComplete.connect([&](bool) {
- clientPipe->Write({uv::Buffer(message), uv::Buffer(message2)},
- [&](auto bufs, uv::Error) {});
+ clientPipe->Write({{message}, {message2}}, [&](auto bufs, uv::Error) {});
});
loop->Run();
@@ -365,7 +369,7 @@
TEST_F(WebSocketServerTest, ReceiveFragmentInvalidIncomplete) {
int gotCallback = 0;
setupWebSocket = [&] {
- ws->closed.connect([&](uint16_t code, StringRef reason) {
+ ws->closed.connect([&](uint16_t code, std::string_view reason) {
++gotCallback;
ASSERT_EQ(code, 1002) << "reason: " << reason;
});
@@ -374,9 +378,8 @@
auto message2 = BuildMessage(0x00, false, true, {});
auto message3 = BuildMessage(0x01, true, true, {});
resp.headersComplete.connect([&](bool) {
- clientPipe->Write(
- {uv::Buffer(message), uv::Buffer(message2), uv::Buffer(message3)},
- [&](auto bufs, uv::Error) {});
+ clientPipe->Write({{message}, {message2}, {message3}},
+ [&](auto bufs, uv::Error) {});
});
loop->Run();
@@ -396,7 +399,7 @@
combData.insert(combData.end(), data3.begin(), data3.end());
setupWebSocket = [&] {
- ws->binary.connect([&](ArrayRef<uint8_t> inData, bool fin) {
+ ws->binary.connect([&](auto inData, bool fin) {
++gotCallback;
ws->Terminate();
ASSERT_TRUE(fin);
@@ -409,9 +412,8 @@
auto message2 = BuildMessage(0x00, false, true, data2);
auto message3 = BuildMessage(0x00, true, true, data3);
resp.headersComplete.connect([&](bool) {
- clientPipe->Write(
- {uv::Buffer(message), uv::Buffer(message2), uv::Buffer(message3)},
- [&](auto bufs, uv::Error) {});
+ clientPipe->Write({{message}, {message2}, {message3}},
+ [&](auto bufs, uv::Error) {});
});
loop->Run();
@@ -432,7 +434,7 @@
setupWebSocket = [&] {
ws->SetCombineFragments(false);
- ws->binary.connect([&](ArrayRef<uint8_t> inData, bool fin) {
+ ws->binary.connect([&](auto inData, bool fin) {
std::vector<uint8_t> recvData{inData.begin(), inData.end()};
switch (++gotCallback) {
case 1:
@@ -459,9 +461,8 @@
auto message2 = BuildMessage(0x00, false, true, data2);
auto message3 = BuildMessage(0x00, true, true, data3);
resp.headersComplete.connect([&](bool) {
- clientPipe->Write(
- {uv::Buffer(message), uv::Buffer(message2), uv::Buffer(message3)},
- [&](auto bufs, uv::Error) {});
+ clientPipe->Write({{message}, {message2}, {message3}},
+ [&](auto bufs, uv::Error) {});
});
loop->Run();
@@ -483,14 +484,14 @@
ws->Terminate();
FAIL() << "Should not have gotten unmasked message";
});
- ws->closed.connect([&](uint16_t code, StringRef reason) {
+ ws->closed.connect([&](uint16_t code, std::string_view reason) {
++gotCallback;
ASSERT_EQ(code, 1009) << "reason: " << reason;
});
};
auto message = BuildMessage(0x01, true, true, data);
resp.headersComplete.connect([&](bool) {
- clientPipe->Write(uv::Buffer(message), [&](auto bufs, uv::Error) {});
+ clientPipe->Write({{message}}, [&](auto bufs, uv::Error) {});
});
loop->Run();
@@ -508,7 +509,7 @@
ws->Terminate();
FAIL() << "Should not have gotten unmasked message";
});
- ws->closed.connect([&](uint16_t code, StringRef reason) {
+ ws->closed.connect([&](uint16_t code, std::string_view reason) {
++gotCallback;
ASSERT_EQ(code, 1009) << "reason: " << reason;
});
@@ -516,8 +517,7 @@
auto message = BuildMessage(0x01, false, true, data);
auto message2 = BuildMessage(0x00, true, true, data);
resp.headersComplete.connect([&](bool) {
- clientPipe->Write({uv::Buffer(message), uv::Buffer(message2)},
- [&](auto bufs, uv::Error) {});
+ clientPipe->Write({{message}, {message2}}, [&](auto bufs, uv::Error) {});
});
loop->Run();
@@ -539,8 +539,8 @@
int gotCallback = 0;
std::vector<uint8_t> data(GetParam(), ' ');
setupWebSocket = [&] {
- ws->open.connect([&](StringRef) {
- ws->SendText(uv::Buffer(data), [&](auto bufs, uv::Error) {
+ ws->open.connect([&](std::string_view) {
+ ws->SendText({{data}}, [&](auto bufs, uv::Error) {
++gotCallback;
ws->Terminate();
ASSERT_FALSE(bufs.empty());
@@ -560,8 +560,8 @@
int gotCallback = 0;
std::vector<uint8_t> data(GetParam(), 0x03u);
setupWebSocket = [&] {
- ws->open.connect([&](StringRef) {
- ws->SendBinary(uv::Buffer(data), [&](auto bufs, uv::Error) {
+ ws->open.connect([&](std::string_view) {
+ ws->SendBinary({{data}}, [&](auto bufs, uv::Error) {
++gotCallback;
ws->Terminate();
ASSERT_FALSE(bufs.empty());
@@ -581,8 +581,8 @@
int gotCallback = 0;
std::vector<uint8_t> data(GetParam(), 0x03u);
setupWebSocket = [&] {
- ws->open.connect([&](StringRef) {
- ws->SendPing(uv::Buffer(data), [&](auto bufs, uv::Error) {
+ ws->open.connect([&](std::string_view) {
+ ws->SendPing({{data}}, [&](auto bufs, uv::Error) {
++gotCallback;
ws->Terminate();
ASSERT_FALSE(bufs.empty());
@@ -602,8 +602,8 @@
int gotCallback = 0;
std::vector<uint8_t> data(GetParam(), 0x03u);
setupWebSocket = [&] {
- ws->open.connect([&](StringRef) {
- ws->SendPong(uv::Buffer(data), [&](auto bufs, uv::Error) {
+ ws->open.connect([&](std::string_view) {
+ ws->SendPong({{data}}, [&](auto bufs, uv::Error) {
++gotCallback;
ws->Terminate();
ASSERT_FALSE(bufs.empty());
@@ -623,18 +623,18 @@
int gotCallback = 0;
std::vector<uint8_t> data(GetParam(), ' ');
setupWebSocket = [&] {
- ws->text.connect([&](StringRef inData, bool fin) {
+ ws->text.connect([&](std::string_view inData, bool fin) {
++gotCallback;
ws->Terminate();
ASSERT_TRUE(fin);
std::vector<uint8_t> recvData;
- recvData.insert(recvData.end(), inData.bytes_begin(), inData.bytes_end());
+ recvData.insert(recvData.end(), inData.begin(), inData.end());
ASSERT_EQ(data, recvData);
});
};
auto message = BuildMessage(0x01, true, true, data);
resp.headersComplete.connect([&](bool) {
- clientPipe->Write(uv::Buffer(message), [&](auto bufs, uv::Error) {});
+ clientPipe->Write({{message}}, [&](auto bufs, uv::Error) {});
});
loop->Run();
@@ -646,7 +646,7 @@
int gotCallback = 0;
std::vector<uint8_t> data(GetParam(), 0x03u);
setupWebSocket = [&] {
- ws->binary.connect([&](ArrayRef<uint8_t> inData, bool fin) {
+ ws->binary.connect([&](auto inData, bool fin) {
++gotCallback;
ws->Terminate();
ASSERT_TRUE(fin);
@@ -656,7 +656,7 @@
};
auto message = BuildMessage(0x02, true, true, data);
resp.headersComplete.connect([&](bool) {
- clientPipe->Write(uv::Buffer(message), [&](auto bufs, uv::Error) {});
+ clientPipe->Write({{message}}, [&](auto bufs, uv::Error) {});
});
loop->Run();
@@ -668,7 +668,7 @@
int gotCallback = 0;
std::vector<uint8_t> data(GetParam(), 0x03u);
setupWebSocket = [&] {
- ws->ping.connect([&](ArrayRef<uint8_t> inData) {
+ ws->ping.connect([&](auto inData) {
++gotCallback;
ws->Terminate();
std::vector<uint8_t> recvData{inData.begin(), inData.end()};
@@ -677,7 +677,7 @@
};
auto message = BuildMessage(0x09, true, true, data);
resp.headersComplete.connect([&](bool) {
- clientPipe->Write(uv::Buffer(message), [&](auto bufs, uv::Error) {});
+ clientPipe->Write({{message}}, [&](auto bufs, uv::Error) {});
});
loop->Run();
@@ -689,7 +689,7 @@
int gotCallback = 0;
std::vector<uint8_t> data(GetParam(), 0x03u);
setupWebSocket = [&] {
- ws->pong.connect([&](ArrayRef<uint8_t> inData) {
+ ws->pong.connect([&](auto inData) {
++gotCallback;
ws->Terminate();
std::vector<uint8_t> recvData{inData.begin(), inData.end()};
@@ -698,7 +698,7 @@
};
auto message = BuildMessage(0x0a, true, true, data);
resp.headersComplete.connect([&](bool) {
- clientPipe->Write(uv::Buffer(message), [&](auto bufs, uv::Error) {});
+ clientPipe->Write({{message}}, [&](auto bufs, uv::Error) {});
});
loop->Run();
@@ -714,18 +714,18 @@
int gotCallback = 0;
std::vector<uint8_t> data(GetParam(), ' ');
setupWebSocket = [&] {
- ws->text.connect([&](StringRef, bool) {
+ ws->text.connect([&](std::string_view, bool) {
ws->Terminate();
FAIL() << "Should not have gotten unmasked message";
});
- ws->closed.connect([&](uint16_t code, StringRef reason) {
+ ws->closed.connect([&](uint16_t code, std::string_view reason) {
++gotCallback;
ASSERT_EQ(code, 1002) << "reason: " << reason;
});
};
auto message = BuildMessage(0x01, true, false, data);
resp.headersComplete.connect([&](bool) {
- clientPipe->Write(uv::Buffer(message), [&](auto bufs, uv::Error) {});
+ clientPipe->Write({{message}}, [&](auto bufs, uv::Error) {});
});
loop->Run();
diff --git a/wpiutil/src/test/native/cpp/WebSocketTest.cpp b/wpiutil/src/test/native/cpp/WebSocketTest.cpp
index c27bac0..b5d5e4e 100644
--- a/wpiutil/src/test/native/cpp/WebSocketTest.cpp
+++ b/wpiutil/src/test/native/cpp/WebSocketTest.cpp
@@ -1,15 +1,13 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "wpi/WebSocket.h" // NOLINT(build/include_order)
#include "WebSocketTest.h"
#include "wpi/HttpParser.h"
+#include "wpi/StringExtras.h"
namespace wpi {
@@ -38,15 +36,19 @@
data.push_back(len & 0xff);
} else {
data.push_back(127u | (masking ? 0x80u : 0x00u));
- for (int i = 56; i >= 0; i -= 8) data.push_back((len >> i) & 0xff);
+ for (int i = 56; i >= 0; i -= 8) {
+ data.push_back((len >> i) & 0xff);
+ }
}
- if (masking) data.insert(data.end(), &testMask[0], &testMask[4]);
+ if (masking) {
+ data.insert(data.end(), &testMask[0], &testMask[4]);
+ }
return data;
}
std::vector<uint8_t> WebSocketTest::BuildMessage(uint8_t opcode, bool fin,
bool masking,
- ArrayRef<uint8_t> data) {
+ span<const uint8_t> data) {
auto finalData = BuildHeader(opcode, fin, masking, data.size());
size_t headerSize = finalData.size();
finalData.insert(finalData.end(), data.begin(), data.end());
@@ -56,7 +58,9 @@
int n = 0;
for (size_t i = headerSize, end = finalData.size(); i < end; ++i) {
finalData[i] ^= mask[n++];
- if (n >= 4) n = 0;
+ if (n >= 4) {
+ n = 0;
+ }
}
}
return finalData;
@@ -64,17 +68,22 @@
// If the message is masked, changes the mask to match the mask set by
// BuildHeader() by unmasking and remasking.
-void WebSocketTest::AdjustMasking(MutableArrayRef<uint8_t> message) {
- if (message.size() < 2) return;
- if ((message[1] & 0x80) == 0) return; // not masked
+void WebSocketTest::AdjustMasking(span<uint8_t> message) {
+ if (message.size() < 2) {
+ return;
+ }
+ if ((message[1] & 0x80) == 0) {
+ return; // not masked
+ }
size_t maskPos;
uint8_t len = message[1] & 0x7f;
- if (len == 126)
+ if (len == 126) {
maskPos = 4;
- else if (len == 127)
+ } else if (len == 127) {
maskPos = 10;
- else
+ } else {
maskPos = 2;
+ }
uint8_t mask[4] = {message[maskPos], message[maskPos + 1],
message[maskPos + 2], message[maskPos + 3]};
message[maskPos] = testMask[0];
@@ -82,9 +91,11 @@
message[maskPos + 2] = testMask[2];
message[maskPos + 3] = testMask[3];
int n = 0;
- for (auto& ch : message.slice(maskPos + 4)) {
+ for (auto& ch : message.subspan(maskPos + 4)) {
ch ^= mask[n] ^ testMask[n];
- if (++n >= 4) n = 0;
+ if (++n >= 4) {
+ n = 0;
+ }
}
}
@@ -96,24 +107,24 @@
int gotVersion = 0;
HttpParser req{HttpParser::kRequest};
- req.url.connect([](StringRef url) { ASSERT_EQ(url, "/test"); });
- req.header.connect([&](StringRef name, StringRef value) {
- if (name.equals_lower("host")) {
+ req.url.connect([](std::string_view url) { ASSERT_EQ(url, "/test"); });
+ req.header.connect([&](std::string_view name, std::string_view value) {
+ if (equals_lower(name, "host")) {
ASSERT_EQ(value, pipeName);
++gotHost;
- } else if (name.equals_lower("upgrade")) {
+ } else if (equals_lower(name, "upgrade")) {
ASSERT_EQ(value, "websocket");
++gotUpgrade;
- } else if (name.equals_lower("connection")) {
+ } else if (equals_lower(name, "connection")) {
ASSERT_EQ(value, "Upgrade");
++gotConnection;
- } else if (name.equals_lower("sec-websocket-key")) {
+ } else if (equals_lower(name, "sec-websocket-key")) {
++gotKey;
- } else if (name.equals_lower("sec-websocket-version")) {
+ } else if (equals_lower(name, "sec-websocket-version")) {
ASSERT_EQ(value, "13");
++gotVersion;
} else {
- FAIL() << "unexpected header " << name.str();
+ FAIL() << "unexpected header " << name;
}
});
req.headersComplete.connect([&](bool) { Finish(); });
@@ -122,8 +133,10 @@
auto conn = serverPipe->Accept();
conn->StartRead();
conn->data.connect([&](uv::Buffer& buf, size_t size) {
- req.Execute(StringRef{buf.base, size});
- if (req.HasError()) Finish();
+ req.Execute(std::string_view{buf.base, size});
+ if (req.HasError()) {
+ Finish();
+ }
ASSERT_EQ(req.GetError(), HPE_OK) << http_errno_name(req.GetError());
});
});
@@ -133,7 +146,9 @@
loop->Run();
- if (HasFatalFailure()) return;
+ if (HasFatalFailure()) {
+ return;
+ }
ASSERT_EQ(gotHost, 1);
ASSERT_EQ(gotUpgrade, 1);
ASSERT_EQ(gotConnection, 1);
@@ -145,11 +160,11 @@
int gotExtra1 = 0;
int gotExtra2 = 0;
HttpParser req{HttpParser::kRequest};
- req.header.connect([&](StringRef name, StringRef value) {
- if (name.equals("Extra1")) {
+ req.header.connect([&](std::string_view name, std::string_view value) {
+ if (equals(name, "Extra1")) {
ASSERT_EQ(value, "Data1");
++gotExtra1;
- } else if (name.equals("Extra2")) {
+ } else if (equals(name, "Extra2")) {
ASSERT_EQ(value, "Data2");
++gotExtra2;
}
@@ -160,24 +175,28 @@
auto conn = serverPipe->Accept();
conn->StartRead();
conn->data.connect([&](uv::Buffer& buf, size_t size) {
- req.Execute(StringRef{buf.base, size});
- if (req.HasError()) Finish();
+ req.Execute(std::string_view{buf.base, size});
+ if (req.HasError()) {
+ Finish();
+ }
ASSERT_EQ(req.GetError(), HPE_OK) << http_errno_name(req.GetError());
});
});
clientPipe->Connect(pipeName, [&]() {
WebSocket::ClientOptions options;
- SmallVector<std::pair<StringRef, StringRef>, 4> extraHeaders;
+ SmallVector<std::pair<std::string_view, std::string_view>, 4> extraHeaders;
extraHeaders.emplace_back("Extra1", "Data1");
extraHeaders.emplace_back("Extra2", "Data2");
options.extraHeaders = extraHeaders;
- auto ws = WebSocket::CreateClient(*clientPipe, "/test", pipeName,
- ArrayRef<StringRef>{}, options);
+ auto ws =
+ WebSocket::CreateClient(*clientPipe, "/test", pipeName, {}, options);
});
loop->Run();
- if (HasFatalFailure()) return;
+ if (HasFatalFailure()) {
+ return;
+ }
ASSERT_EQ(gotExtra1, 1);
ASSERT_EQ(gotExtra2, 1);
}
@@ -188,9 +207,9 @@
clientPipe->Connect(pipeName, [&]() {
WebSocket::ClientOptions options;
options.handshakeTimeout = uv::Timer::Time{100};
- auto ws = WebSocket::CreateClient(*clientPipe, "/test", pipeName,
- ArrayRef<StringRef>{}, options);
- ws->closed.connect([&](uint16_t code, StringRef) {
+ auto ws =
+ WebSocket::CreateClient(*clientPipe, "/test", pipeName, {}, options);
+ ws->closed.connect([&](uint16_t code, std::string_view) {
Finish();
++gotClosed;
ASSERT_EQ(code, 1006);
@@ -199,7 +218,9 @@
loop->Run();
- if (HasFatalFailure()) return;
+ if (HasFatalFailure()) {
+ return;
+ }
ASSERT_EQ(gotClosed, 1);
}
@@ -211,22 +232,22 @@
int gotOpen = 0;
HttpParser resp{HttpParser::kResponse};
- resp.status.connect([&](StringRef status) {
+ resp.status.connect([&](std::string_view status) {
++gotStatus;
ASSERT_EQ(resp.GetStatusCode(), 101u) << "status: " << status;
});
- resp.header.connect([&](StringRef name, StringRef value) {
- if (name.equals_lower("upgrade")) {
+ resp.header.connect([&](std::string_view name, std::string_view value) {
+ if (equals_lower(name, "upgrade")) {
ASSERT_EQ(value, "websocket");
++gotUpgrade;
- } else if (name.equals_lower("connection")) {
+ } else if (equals_lower(name, "connection")) {
ASSERT_EQ(value, "Upgrade");
++gotConnection;
- } else if (name.equals_lower("sec-websocket-accept")) {
+ } else if (equals_lower(name, "sec-websocket-accept")) {
ASSERT_EQ(value, "s3pPLMBiTxaQ9kYGzzhZRbK+xOo=");
++gotAccept;
} else {
- FAIL() << "unexpected header " << name.str();
+ FAIL() << "unexpected header " << name;
}
});
resp.headersComplete.connect([&](bool) { Finish(); });
@@ -234,7 +255,7 @@
serverPipe->Listen([&]() {
auto conn = serverPipe->Accept();
auto ws = WebSocket::CreateServer(*conn, "dGhlIHNhbXBsZSBub25jZQ==", "13");
- ws->open.connect([&](StringRef protocol) {
+ ws->open.connect([&](std::string_view protocol) {
++gotOpen;
ASSERT_TRUE(protocol.empty());
});
@@ -242,15 +263,19 @@
clientPipe->Connect(pipeName, [&] {
clientPipe->StartRead();
clientPipe->data.connect([&](uv::Buffer& buf, size_t size) {
- resp.Execute(StringRef{buf.base, size});
- if (resp.HasError()) Finish();
+ resp.Execute(std::string_view{buf.base, size});
+ if (resp.HasError()) {
+ Finish();
+ }
ASSERT_EQ(resp.GetError(), HPE_OK) << http_errno_name(resp.GetError());
});
});
loop->Run();
- if (HasFatalFailure()) return;
+ if (HasFatalFailure()) {
+ return;
+ }
ASSERT_EQ(gotStatus, 1);
ASSERT_EQ(gotUpgrade, 1);
ASSERT_EQ(gotConnection, 1);
@@ -263,8 +288,8 @@
int gotOpen = 0;
HttpParser resp{HttpParser::kResponse};
- resp.header.connect([&](StringRef name, StringRef value) {
- if (name.equals_lower("sec-websocket-protocol")) {
+ resp.header.connect([&](std::string_view name, std::string_view value) {
+ if (equals_lower(name, "sec-websocket-protocol")) {
++gotProtocol;
ASSERT_EQ(value, "myProtocol");
}
@@ -274,7 +299,7 @@
serverPipe->Listen([&]() {
auto conn = serverPipe->Accept();
auto ws = WebSocket::CreateServer(*conn, "foo", "13", "myProtocol");
- ws->open.connect([&](StringRef protocol) {
+ ws->open.connect([&](std::string_view protocol) {
++gotOpen;
ASSERT_EQ(protocol, "myProtocol");
});
@@ -282,15 +307,19 @@
clientPipe->Connect(pipeName, [&] {
clientPipe->StartRead();
clientPipe->data.connect([&](uv::Buffer& buf, size_t size) {
- resp.Execute(StringRef{buf.base, size});
- if (resp.HasError()) Finish();
+ resp.Execute(std::string_view{buf.base, size});
+ if (resp.HasError()) {
+ Finish();
+ }
ASSERT_EQ(resp.GetError(), HPE_OK) << http_errno_name(resp.GetError());
});
});
loop->Run();
- if (HasFatalFailure()) return;
+ if (HasFatalFailure()) {
+ return;
+ }
ASSERT_EQ(gotProtocol, 1);
ASSERT_EQ(gotOpen, 1);
}
@@ -301,19 +330,19 @@
int gotUpgrade = 0;
HttpParser resp{HttpParser::kResponse};
- resp.status.connect([&](StringRef status) {
+ resp.status.connect([&](std::string_view status) {
++gotStatus;
ASSERT_EQ(resp.GetStatusCode(), 426u) << "status: " << status;
});
- resp.header.connect([&](StringRef name, StringRef value) {
- if (name.equals_lower("sec-websocket-version")) {
+ resp.header.connect([&](std::string_view name, std::string_view value) {
+ if (equals_lower(name, "sec-websocket-version")) {
++gotVersion;
ASSERT_EQ(value, "13");
- } else if (name.equals_lower("upgrade")) {
+ } else if (equals_lower(name, "upgrade")) {
++gotUpgrade;
ASSERT_EQ(value, "WebSocket");
} else {
- FAIL() << "unexpected header " << name.str();
+ FAIL() << "unexpected header " << name;
}
});
resp.headersComplete.connect([&](bool) { Finish(); });
@@ -321,7 +350,7 @@
serverPipe->Listen([&] {
auto conn = serverPipe->Accept();
auto ws = WebSocket::CreateServer(*conn, "foo", "14");
- ws->open.connect([&](StringRef) {
+ ws->open.connect([&](std::string_view) {
Finish();
FAIL();
});
@@ -329,15 +358,19 @@
clientPipe->Connect(pipeName, [&] {
clientPipe->StartRead();
clientPipe->data.connect([&](uv::Buffer& buf, size_t size) {
- resp.Execute(StringRef{buf.base, size});
- if (resp.HasError()) Finish();
+ resp.Execute(std::string_view{buf.base, size});
+ if (resp.HasError()) {
+ Finish();
+ }
ASSERT_EQ(resp.GetError(), HPE_OK) << http_errno_name(resp.GetError());
});
});
loop->Run();
- if (HasFatalFailure()) return;
+ if (HasFatalFailure()) {
+ return;
+ }
ASSERT_EQ(gotStatus, 1);
ASSERT_EQ(gotVersion, 1);
ASSERT_EQ(gotUpgrade, 1);
diff --git a/wpiutil/src/test/native/cpp/WebSocketTest.h b/wpiutil/src/test/native/cpp/WebSocketTest.h
index 8b40440..fda4473 100644
--- a/wpiutil/src/test/native/cpp/WebSocketTest.h
+++ b/wpiutil/src/test/native/cpp/WebSocketTest.h
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#pragma once
@@ -12,7 +9,7 @@
#include <vector>
#include "gtest/gtest.h"
-#include "wpi/ArrayRef.h"
+#include "wpi/span.h"
#include "wpi/uv/Loop.h"
#include "wpi/uv/Pipe.h"
#include "wpi/uv/Timer.h"
@@ -51,7 +48,7 @@
failTimer->Unreference();
}
- ~WebSocketTest() { Finish(); }
+ ~WebSocketTest() override { Finish(); }
void Finish() {
loop->Walk([](uv::Handle& it) { it.Close(); });
@@ -61,8 +58,8 @@
bool masking, uint64_t len);
static std::vector<uint8_t> BuildMessage(uint8_t opcode, bool fin,
bool masking,
- ArrayRef<uint8_t> data);
- static void AdjustMasking(MutableArrayRef<uint8_t> message);
+ span<const uint8_t> data);
+ static void AdjustMasking(span<uint8_t> message);
static const uint8_t testMask[4];
std::shared_ptr<uv::Loop> loop;
diff --git a/wpiutil/src/test/native/cpp/WorkerThreadTest.cpp b/wpiutil/src/test/native/cpp/WorkerThreadTest.cpp
index 610029c..9bc9a17 100644
--- a/wpiutil/src/test/native/cpp/WorkerThreadTest.cpp
+++ b/wpiutil/src/test/native/cpp/WorkerThreadTest.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "wpi/WorkerThread.h" // NOLINT(build/include_order)
@@ -15,14 +12,14 @@
namespace wpi {
-TEST(WorkerThread, Future) {
+TEST(WorkerThreadTest, Future) {
WorkerThread<int(bool)> worker;
future<int> f =
worker.QueueWork([](bool v) -> int { return v ? 1 : 2; }, true);
ASSERT_EQ(f.get(), 1);
}
-TEST(WorkerThread, FutureVoid) {
+TEST(WorkerThreadTest, FutureVoid) {
int callbacks = 0;
WorkerThread<void(int)> worker;
future<void> f = worker.QueueWork(
@@ -35,7 +32,7 @@
ASSERT_EQ(callbacks, 1);
}
-TEST(WorkerThread, Loop) {
+TEST(WorkerThreadTest, Loop) {
int callbacks = 0;
WorkerThread<int(bool)> worker;
auto loop = uv::Loop::Create();
@@ -53,7 +50,7 @@
ASSERT_EQ(callbacks, 1);
}
-TEST(WorkerThread, LoopVoid) {
+TEST(WorkerThreadTest, LoopVoid) {
int callbacks = 0;
WorkerThread<void(bool)> worker;
auto loop = uv::Loop::Create();
diff --git a/wpiutil/src/test/native/cpp/future_test.cpp b/wpiutil/src/test/native/cpp/future_test.cpp
index b9b79a8..8817f2d 100644
--- a/wpiutil/src/test/native/cpp/future_test.cpp
+++ b/wpiutil/src/test/native/cpp/future_test.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "wpi/future.h" // NOLINT(build/include_order)
@@ -13,7 +10,7 @@
namespace wpi {
-TEST(Future, Then) {
+TEST(FutureTest, Then) {
promise<bool> inPromise;
future<int> outFuture =
inPromise.get_future().then([](bool v) { return v ? 5 : 6; });
@@ -22,7 +19,7 @@
ASSERT_EQ(outFuture.get(), 5);
}
-TEST(Future, ThenSame) {
+TEST(FutureTest, ThenSame) {
promise<bool> inPromise;
future<bool> outFuture =
inPromise.get_future().then([](bool v) { return !v; });
@@ -31,7 +28,7 @@
ASSERT_EQ(outFuture.get(), false);
}
-TEST(Future, ThenFromVoid) {
+TEST(FutureTest, ThenFromVoid) {
promise<void> inPromise;
future<int> outFuture = inPromise.get_future().then([] { return 5; });
@@ -39,7 +36,7 @@
ASSERT_EQ(outFuture.get(), 5);
}
-TEST(Future, ThenToVoid) {
+TEST(FutureTest, ThenToVoid) {
promise<bool> inPromise;
future<void> outFuture = inPromise.get_future().then([](bool v) {});
@@ -47,7 +44,7 @@
ASSERT_TRUE(outFuture.is_ready());
}
-TEST(Future, ThenVoidVoid) {
+TEST(FutureTest, ThenVoidVoid) {
promise<void> inPromise;
future<void> outFuture = inPromise.get_future().then([] {});
@@ -55,7 +52,7 @@
ASSERT_TRUE(outFuture.is_ready());
}
-TEST(Future, Implicit) {
+TEST(FutureTest, Implicit) {
promise<bool> inPromise;
future<int> outFuture = inPromise.get_future();
@@ -63,7 +60,7 @@
ASSERT_EQ(outFuture.get(), 1);
}
-TEST(Future, MoveSame) {
+TEST(FutureTest, MoveSame) {
promise<bool> inPromise;
future<bool> outFuture1 = inPromise.get_future();
future<bool> outFuture(std::move(outFuture1));
@@ -72,7 +69,7 @@
ASSERT_EQ(outFuture.get(), true);
}
-TEST(Future, MoveVoid) {
+TEST(FutureTest, MoveVoid) {
promise<void> inPromise;
future<void> outFuture1 = inPromise.get_future();
future<void> outFuture(std::move(outFuture1));
diff --git a/wpiutil/src/test/native/cpp/hostname.cpp b/wpiutil/src/test/native/cpp/hostname.cpp
index d5ec535..29cceb1 100644
--- a/wpiutil/src/test/native/cpp/hostname.cpp
+++ b/wpiutil/src/test/native/cpp/hostname.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "wpi/hostname.h"
@@ -12,7 +9,9 @@
#include "wpi/SmallVector.h"
namespace wpi {
-TEST(HostNameTest, HostNameNotEmpty) { ASSERT_NE(GetHostname(), ""); }
+TEST(HostNameTest, HostNameNotEmpty) {
+ ASSERT_NE(GetHostname(), "");
+}
TEST(HostNameTest, HostNameNotEmptySmallVector) {
SmallVector<char, 256> name;
ASSERT_NE(GetHostname(name), "");
diff --git a/wpiutil/src/test/native/cpp/json/unit-readme.cpp b/wpiutil/src/test/native/cpp/json/unit-readme.cpp
index ecb7f79..14d2b1b 100644
--- a/wpiutil/src/test/native/cpp/json/unit-readme.cpp
+++ b/wpiutil/src/test/native/cpp/json/unit-readme.cpp
@@ -200,7 +200,7 @@
{
std::vector<int> c_vector {1, 2, 3, 4};
json j_vec(c_vector);
- json j_vec2(wpi::makeArrayRef(c_vector));
+ json j_vec2(wpi::span<const int>(c_vector.data(), c_vector.size()));
// [1, 2, 3, 4]
std::deque<float> c_deque {1.2f, 2.3f, 3.4f, 5.6f};
diff --git a/wpiutil/src/test/native/cpp/json/unit-unicode.cpp b/wpiutil/src/test/native/cpp/json/unit-unicode.cpp
index e0179b6..6755fe2 100644
--- a/wpiutil/src/test/native/cpp/json/unit-unicode.cpp
+++ b/wpiutil/src/test/native/cpp/json/unit-unicode.cpp
@@ -37,7 +37,7 @@
#include "unit-json.h"
using wpi::json;
-#include "wpi/Format.h"
+#include "fmt/format.h"
#include "wpi/StringExtras.h"
#include "wpi/raw_ostream.h"
@@ -919,11 +919,7 @@
// reverse solidus, followed by the lowercase letter u, followed
// by four hexadecimal digits that encode the character's code
// point
- std::string s;
- wpi::raw_string_ostream ss(s);
- ss << "\\u" << wpi::format_hex_no_prefix(cp, 4);
- ss.flush();
- return s;
+ return fmt::format("\\u{:04x}", cp);
}
// correct sequences
diff --git a/wpiutil/src/test/native/cpp/leb128Test.cpp b/wpiutil/src/test/native/cpp/leb128Test.cpp
index a3a7ed0..cc537ae 100644
--- a/wpiutil/src/test/native/cpp/leb128Test.cpp
+++ b/wpiutil/src/test/native/cpp/leb128Test.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2015-2018 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
//===- llvm/unittest/Support/LEB128Test.cpp - LEB128 function tests -------===//
//
@@ -17,23 +14,23 @@
#include <stdint.h>
#include <string>
+#include <string_view>
#include "gtest/gtest.h"
#include "wpi/SmallString.h"
-#include "wpi/StringRef.h"
#include "wpi/leb128.h"
#include "wpi/raw_istream.h"
namespace wpi {
TEST(LEB128Test, WriteUleb128) {
-#define EXPECT_ULEB128_EQ(EXPECTED, VALUE, PAD) \
- do { \
- StringRef expected(EXPECTED, sizeof(EXPECTED) - 1); \
- SmallString<32> buf; \
- size_t size = WriteUleb128(buf, VALUE); \
- EXPECT_EQ(size, buf.size()); \
- EXPECT_EQ(expected, buf.str()); \
+#define EXPECT_ULEB128_EQ(EXPECTED, VALUE, PAD) \
+ do { \
+ std::string_view expected(EXPECTED, sizeof(EXPECTED) - 1); \
+ SmallString<32> buf; \
+ size_t size = WriteUleb128(buf, VALUE); \
+ EXPECT_EQ(size, buf.size()); \
+ EXPECT_EQ(expected, buf.str()); \
} while (0)
// Write ULEB128
@@ -48,6 +45,8 @@
EXPECT_ULEB128_EQ("\xff\x01", 0xff, 0);
EXPECT_ULEB128_EQ("\x80\x02", 0x100, 0);
EXPECT_ULEB128_EQ("\x81\x02", 0x101, 0);
+ EXPECT_ULEB128_EQ("\x80\x41", 0x2080, 0);
+ EXPECT_ULEB128_EQ("\x80\xc1\x80\x80\x10", 0x100002080, 0);
#undef EXPECT_ULEB128_EQ
}
@@ -73,7 +72,8 @@
EXPECT_READ_ULEB128_EQ(0xffu, "\xff\x01");
EXPECT_READ_ULEB128_EQ(0x100u, "\x80\x02");
EXPECT_READ_ULEB128_EQ(0x101u, "\x81\x02");
- EXPECT_READ_ULEB128_EQ(8320u, "\x80\xc1\x80\x80\x10");
+ EXPECT_READ_ULEB128_EQ(0x2080u, "\x80\x41");
+ EXPECT_READ_ULEB128_EQ(0x100002080u, "\x80\xc1\x80\x80\x10");
#undef EXPECT_READ_ULEB128_EQ
}
diff --git a/wpiutil/src/test/native/cpp/main.cpp b/wpiutil/src/test/native/cpp/main.cpp
index 1e5ecf0..09072ee 100644
--- a/wpiutil/src/test/native/cpp/main.cpp
+++ b/wpiutil/src/test/native/cpp/main.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2015-2018 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "gtest/gtest.h"
diff --git a/wpiutil/src/test/native/cpp/priority_mutex_test.cpp b/wpiutil/src/test/native/cpp/priority_mutex_test.cpp
index 448a757..832e8f3 100644
--- a/wpiutil/src/test/native/cpp/priority_mutex_test.cpp
+++ b/wpiutil/src/test/native/cpp/priority_mutex_test.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include <wpi/priority_mutex.h> // NOLINT(build/include_order)
@@ -58,7 +55,7 @@
void SetThreadRealtimePriorityOrDie(int32_t priority) {
struct sched_param param;
- // Set realtime priority for this thread
+ // Set real-time priority for this thread
param.sched_priority = priority + sched_get_priority_min(SCHED_RR);
ASSERT_EQ(pthread_setschedparam(pthread_self(), SCHED_RR, ¶m), 0)
<< ": Failed to set scheduler priority.";
@@ -225,7 +222,7 @@
// TODO: Fix roborio permissions to run as root.
// Priority inversion test.
-TEST(MutexTest, DISABLED_PriorityInversionTest) {
+TEST(MutexTest, DISABLED_PriorityInversion) {
InversionTestRunner<priority_mutex> runner;
std::thread runner_thread(std::ref(runner));
runner_thread.join();
@@ -233,7 +230,7 @@
}
// Verify that the non-priority inversion mutex doesn't pass the test.
-TEST(MutexTest, DISABLED_StdMutexPriorityInversionTest) {
+TEST(MutexTest, DISABLED_StdMutexPriorityInversion) {
InversionTestRunner<std::mutex> runner;
std::thread runner_thread(std::ref(runner));
runner_thread.join();
@@ -250,7 +247,7 @@
}
// Priority inversion test.
-TEST(MutexTest, DISABLED_ReentrantPriorityInversionTest) {
+TEST(MutexTest, DISABLED_ReentrantPriorityInversion) {
InversionTestRunner<priority_recursive_mutex> runner;
std::thread runner_thread(std::ref(runner));
runner_thread.join();
diff --git a/wpiutil/src/test/native/cpp/raw_uv_stream_test.cpp b/wpiutil/src/test/native/cpp/raw_uv_stream_test.cpp
index d1a0f6c..985fb8b 100644
--- a/wpiutil/src/test/native/cpp/raw_uv_stream_test.cpp
+++ b/wpiutil/src/test/native/cpp/raw_uv_stream_test.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "wpi/raw_uv_ostream.h" // NOLINT(build/include_order)
@@ -22,6 +19,10 @@
ASSERT_EQ(bufs[0].base[1], '2');
ASSERT_EQ(bufs[0].base[2], '3');
ASSERT_EQ(bufs[0].base[3], '4');
+
+ for (auto& buf : bufs) {
+ buf.Deallocate();
+ }
}
TEST(RawUvStreamTest, BoundaryWrite) {
@@ -34,6 +35,10 @@
ASSERT_EQ(bufs.size(), 1u);
os << "56";
ASSERT_EQ(bufs.size(), 2u);
+
+ for (auto& buf : bufs) {
+ buf.Deallocate();
+ }
}
TEST(RawUvStreamTest, LargeWrite) {
@@ -43,6 +48,10 @@
ASSERT_EQ(bufs.size(), 2u);
ASSERT_EQ(bufs[1].len, 2u);
ASSERT_EQ(bufs[1].base[0], '5');
+
+ for (auto& buf : bufs) {
+ buf.Deallocate();
+ }
}
TEST(RawUvStreamTest, PrevDataWrite) {
@@ -53,6 +62,10 @@
ASSERT_EQ(bufs.size(), 2u);
ASSERT_EQ(bufs[0].len, 1024u);
ASSERT_EQ(bufs[1].len, 4u);
+
+ for (auto& buf : bufs) {
+ buf.Deallocate();
+ }
}
} // namespace wpi
diff --git a/wpiutil/src/test/native/cpp/sha1Test.cpp b/wpiutil/src/test/native/cpp/sha1Test.cpp
index 08d85fe..0257431 100644
--- a/wpiutil/src/test/native/cpp/sha1Test.cpp
+++ b/wpiutil/src/test/native/cpp/sha1Test.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
/*
test_sha1.cpp - test program of
diff --git a/wpiutil/src/test/native/cpp/sigslot/function-traits.cpp b/wpiutil/src/test/native/cpp/sigslot/function-traits.cpp
index 240e688..f31e296 100644
--- a/wpiutil/src/test/native/cpp/sigslot/function-traits.cpp
+++ b/wpiutil/src/test/native/cpp/sigslot/function-traits.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
/*
@@ -119,7 +116,7 @@
namespace wpi {
-TEST(Signal, FunctionTraits) {
+TEST(SignalTest, FunctionTraits) {
auto l1 = [](int, char, float) {};
auto l2 = [&](int, char, float) mutable {};
auto l3 = [&](auto...) mutable {};
diff --git a/wpiutil/src/test/native/cpp/sigslot/recursive.cpp b/wpiutil/src/test/native/cpp/sigslot/recursive.cpp
index 85ae9a9..82613f2 100644
--- a/wpiutil/src/test/native/cpp/sigslot/recursive.cpp
+++ b/wpiutil/src/test/native/cpp/sigslot/recursive.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
/*
@@ -42,7 +39,7 @@
template <typename T>
struct object {
- object(T i) : v{i} {} // NOLINT(runtime/explicit)
+ object(T i) : v{i} {} // NOLINT
void inc_val(const T& i) {
if (i != v) {
@@ -66,7 +63,7 @@
namespace wpi {
-TEST(Signal, Recursive) {
+TEST(SignalTest, Recursive) {
object<int> i1(-1);
object<int> i2(10);
@@ -78,7 +75,7 @@
ASSERT_EQ(i1.v, i2.v);
}
-TEST(Signal, SelfRecursive) {
+TEST(SignalTest, SelfRecursive) {
int i = 0;
wpi::sig::Signal_r<int> s;
diff --git a/wpiutil/src/test/native/cpp/sigslot/signal-extended.cpp b/wpiutil/src/test/native/cpp/sigslot/signal-extended.cpp
index 1ebbc8e..a0dbdfc 100644
--- a/wpiutil/src/test/native/cpp/sigslot/signal-extended.cpp
+++ b/wpiutil/src/test/native/cpp/sigslot/signal-extended.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
/*
@@ -71,7 +68,7 @@
namespace wpi {
-TEST(SignalExtended, FreeConnection) {
+TEST(SignalExtendedTest, FreeConnection) {
sum = 0;
Signal<int> sig;
sig.connect_extended(f);
@@ -82,7 +79,7 @@
ASSERT_EQ(sum, 1);
}
-TEST(SignalExtended, StaticConnection) {
+TEST(SignalExtendedTest, StaticConnection) {
sum = 0;
Signal<int> sig;
sig.connect_extended(&s::sf);
@@ -93,7 +90,7 @@
ASSERT_EQ(sum, 1);
}
-TEST(SignalExtended, PmfConnection) {
+TEST(SignalExtendedTest, PmfConnection) {
sum = 0;
Signal<int> sig;
s p;
@@ -105,7 +102,7 @@
ASSERT_EQ(sum, 1);
}
-TEST(SignalExtended, FunctionObjectConnection) {
+TEST(SignalExtendedTest, FunctionObjectConnection) {
sum = 0;
Signal<int> sig;
sig.connect_extended(o{});
@@ -116,7 +113,7 @@
ASSERT_EQ(sum, 1);
}
-TEST(SignalExtended, LambdaConnection) {
+TEST(SignalExtendedTest, LambdaConnection) {
sum = 0;
Signal<int> sig;
diff --git a/wpiutil/src/test/native/cpp/sigslot/signal-threaded.cpp b/wpiutil/src/test/native/cpp/sigslot/signal-threaded.cpp
index c4f7cdb..00001a8 100644
--- a/wpiutil/src/test/native/cpp/sigslot/signal-threaded.cpp
+++ b/wpiutil/src/test/native/cpp/sigslot/signal-threaded.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
/*
@@ -48,16 +45,22 @@
std::atomic<int> sum{0};
-void f(int i) { sum += i; }
+void f(int i) {
+ sum += i;
+}
void emit_many(Signal_mt<int>& sig) {
- for (int i = 0; i < 10000; ++i) sig(1);
+ for (int i = 0; i < 10000; ++i) {
+ sig(1);
+ }
}
void connect_emit(Signal_mt<int>& sig) {
for (int i = 0; i < 100; ++i) {
auto s = sig.connect_scoped(f);
- for (int j = 0; j < 100; ++j) sig(1);
+ for (int j = 0; j < 100; ++j) {
+ sig(1);
+ }
}
}
@@ -65,27 +68,35 @@
namespace wpi {
-TEST(Signal, ThreadedMix) {
+TEST(SignalTest, ThreadedMix) {
sum = 0;
Signal_mt<int> sig;
std::array<std::thread, 10> threads;
- for (auto& t : threads) t = std::thread(connect_emit, std::ref(sig));
+ for (auto& t : threads) {
+ t = std::thread(connect_emit, std::ref(sig));
+ }
- for (auto& t : threads) t.join();
+ for (auto& t : threads) {
+ t.join();
+ }
}
-TEST(Signal, ThreadedEmission) {
+TEST(SignalTest, ThreadedEmission) {
sum = 0;
Signal_mt<int> sig;
sig.connect(f);
std::array<std::thread, 10> threads;
- for (auto& t : threads) t = std::thread(emit_many, std::ref(sig));
+ for (auto& t : threads) {
+ t = std::thread(emit_many, std::ref(sig));
+ }
- for (auto& t : threads) t.join();
+ for (auto& t : threads) {
+ t.join();
+ }
ASSERT_EQ(sum, 100000);
}
diff --git a/wpiutil/src/test/native/cpp/sigslot/signal-tracking.cpp b/wpiutil/src/test/native/cpp/sigslot/signal-tracking.cpp
index 89ffd36..d05ee1a 100644
--- a/wpiutil/src/test/native/cpp/sigslot/signal-tracking.cpp
+++ b/wpiutil/src/test/native/cpp/sigslot/signal-tracking.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
/*
@@ -48,7 +45,9 @@
int sum = 0;
-void f1(int i) { sum += i; }
+void f1(int i) {
+ sum += i;
+}
struct o1 {
void operator()(int i) { sum += 2 * i; }
};
@@ -73,7 +72,7 @@
namespace wpi {
-TEST(Signal, TrackShared) {
+TEST(SignalTest, TrackShared) {
sum = 0;
Signal<int> sig;
@@ -96,7 +95,7 @@
ASSERT_EQ(sum, 5);
}
-TEST(Signal, TrackOther) {
+TEST(SignalTest, TrackOther) {
sum = 0;
Signal<int> sig;
@@ -119,7 +118,7 @@
ASSERT_EQ(sum, 5);
}
-TEST(Signal, TrackOverloadedFunctionObject) {
+TEST(SignalTest, TrackOverloadedFunctionObject) {
sum = 0;
Signal<int> sig;
Signal<double> sig1;
@@ -144,7 +143,7 @@
ASSERT_EQ(sum, 5);
}
-TEST(Signal, TrackGenericLambda) {
+TEST(SignalTest, TrackGenericLambda) {
std::stringstream s;
auto f = [&](auto a, auto... args) {
diff --git a/wpiutil/src/test/native/cpp/sigslot/signal.cpp b/wpiutil/src/test/native/cpp/sigslot/signal.cpp
index a4f9208..cc2ff80 100644
--- a/wpiutil/src/test/native/cpp/sigslot/signal.cpp
+++ b/wpiutil/src/test/native/cpp/sigslot/signal.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
/*
@@ -48,8 +45,12 @@
int sum = 0;
-void f1(int i) { sum += i; }
-void f2(int i) /*noexcept*/ { sum += 2 * i; }
+void f1(int i) {
+ sum += i;
+}
+void f2(int i) /*noexcept*/ {
+ sum += 2 * i;
+}
struct s {
static void s1(int i) { sum += i; }
@@ -99,7 +100,7 @@
namespace wpi {
-TEST(Signal, FreeConnection) {
+TEST(SignalTest, FreeConnection) {
sum = 0;
Signal<int> sig;
@@ -112,7 +113,7 @@
ASSERT_EQ(sum, 4);
}
-TEST(Signal, StaticConnection) {
+TEST(SignalTest, StaticConnection) {
sum = 0;
Signal<int> sig;
@@ -125,7 +126,7 @@
ASSERT_EQ(sum, 4);
}
-TEST(Signal, PmfConnection) {
+TEST(SignalTest, PmfConnection) {
sum = 0;
Signal<int> sig;
s p;
@@ -143,7 +144,7 @@
ASSERT_EQ(sum, 8);
}
-TEST(Signal, ConstPmfConnection) {
+TEST(SignalTest, ConstPmfConnection) {
sum = 0;
Signal<int> sig;
const s p;
@@ -157,7 +158,7 @@
ASSERT_EQ(sum, 4);
}
-TEST(Signal, FunctionObjectConnection) {
+TEST(SignalTest, FunctionObjectConnection) {
sum = 0;
Signal<int> sig;
@@ -174,7 +175,7 @@
ASSERT_EQ(sum, 8);
}
-TEST(Signal, OverloadedFunctionObjectConnection) {
+TEST(SignalTest, OverloadedFunctionObjectConnection) {
sum = 0;
Signal<int> sig;
Signal<double> sig1;
@@ -188,7 +189,7 @@
ASSERT_EQ(sum, 5);
}
-TEST(Signal, LambdaConnection) {
+TEST(SignalTest, LambdaConnection) {
sum = 0;
Signal<int> sig;
@@ -201,7 +202,7 @@
ASSERT_EQ(sum, 4);
}
-TEST(Signal, GenericLambdaConnection) {
+TEST(SignalTest, GenericLambdaConnection) {
std::stringstream s;
auto f = [&](auto a, auto... args) {
@@ -228,7 +229,7 @@
ASSERT_EQ(s.str(), "1foo4.1");
}
-TEST(Signal, LvalueEmission) {
+TEST(SignalTest, LvalueEmission) {
sum = 0;
Signal<int> sig;
@@ -242,7 +243,7 @@
ASSERT_EQ(sum, 4);
}
-TEST(Signal, Mutation) {
+TEST(SignalTest, Mutation) {
int res = 0;
Signal<int&> sig;
@@ -255,7 +256,7 @@
ASSERT_EQ(res, 4);
}
-TEST(Signal, CompatibleArgs) {
+TEST(SignalTest, CompatibleArgs) {
long ll = 0; // NOLINT(runtime/int)
std::string ss;
short ii = 0; // NOLINT(runtime/int)
@@ -275,7 +276,7 @@
ASSERT_EQ(ii, 1);
}
-TEST(Signal, Disconnection) {
+TEST(SignalTest, Disconnection) {
// test removing only connected
{
sum = 0;
@@ -327,7 +328,7 @@
}
}
-TEST(Signal, ScopedConnection) {
+TEST(SignalTest, ScopedConnection) {
sum = 0;
Signal<int> sig;
@@ -360,7 +361,7 @@
ASSERT_EQ(sum, 4);
}
-TEST(Signal, ConnectionBlocking) {
+TEST(SignalTest, ConnectionBlocking) {
sum = 0;
Signal<int> sig;
@@ -378,7 +379,7 @@
ASSERT_EQ(sum, 8);
}
-TEST(Signal, ConnectionBlocker) {
+TEST(SignalTest, ConnectionBlocker) {
sum = 0;
Signal<int> sig;
@@ -397,7 +398,7 @@
ASSERT_EQ(sum, 8);
}
-TEST(Signal, SignalBlocking) {
+TEST(SignalTest, SignalBlocking) {
sum = 0;
Signal<int> sig;
@@ -415,7 +416,7 @@
ASSERT_EQ(sum, 6);
}
-TEST(Signal, AllDisconnection) {
+TEST(SignalTest, AllDisconnection) {
sum = 0;
Signal<int> sig;
@@ -429,7 +430,7 @@
ASSERT_EQ(sum, 3);
}
-TEST(Signal, ConnectionCopyingMoving) {
+TEST(SignalTest, ConnectionCopyingMoving) {
sum = 0;
Signal<int> sig;
@@ -458,7 +459,7 @@
ASSERT_EQ(sum, 9);
}
-TEST(Signal, ScopedConnectionMoving) {
+TEST(SignalTest, ScopedConnectionMoving) {
sum = 0;
Signal<int> sig;
@@ -484,7 +485,7 @@
ASSERT_EQ(sum, 10);
}
-TEST(Signal, SignalMoving) {
+TEST(SignalTest, SignalMoving) {
sum = 0;
Signal<int> sig;
@@ -506,7 +507,7 @@
template <typename T>
struct object {
object();
- object(T i) : v{i} {} // NOLINT(runtime/explicit)
+ object(T i) : v{i} {} // NOLINT
const T& val() const { return v; }
T& val() { return v; }
@@ -524,7 +525,7 @@
Signal<T> s;
};
-TEST(Signal, Loop) {
+TEST(SignalTest, Loop) {
object<int> i1(0);
object<int> i2(3);
diff --git a/wpiutil/src/test/native/cpp/span/test_conversions.cpp b/wpiutil/src/test/native/cpp/span/test_conversions.cpp
new file mode 100644
index 0000000..fa111a7
--- /dev/null
+++ b/wpiutil/src/test/native/cpp/span/test_conversions.cpp
@@ -0,0 +1,46 @@
+#if __has_include(<span>)
+#include <span>
+#endif
+#include "wpi/span.h"
+
+#include "gtest/gtest.h"
+
+void func1(wpi::span<const int> x) {}
+#ifdef __cpp_lib_span
+void func2(std::span<const int> x) {}
+#endif
+
+void func4(wpi::span<int> x) {}
+#ifdef __cpp_lib_span
+void func5(std::span<int> x) {}
+#endif
+
+TEST(Span, ConvertStdSpan) {
+ func1(wpi::span<const int>{});
+ func1(wpi::span<int>{});
+#ifdef __cpp_lib_span
+ func1(std::span<const int>{});
+ func1(std::span<int>{});
+#endif
+
+#ifdef __cpp_lib_span
+ func2(wpi::span<const int>{});
+ func2(wpi::span<int>{});
+ func2(std::span<const int>{});
+ func2(std::span<int>{});
+#endif
+
+ //func4(wpi::span<const int>{});
+ func4(wpi::span<int>{});
+#ifdef __cpp_lib_span
+ //func4(std::span<const int>{});
+ func4(std::span<int>{});
+#endif
+
+#ifdef __cpp_lib_span
+ //func5(wpi::span<const int>{});
+ func5(wpi::span<int>{});
+ //func5(std::span<const int>{});
+ func5(std::span<int>{});
+#endif
+}
diff --git a/wpiutil/src/test/native/cpp/span/test_deduction_guides.cpp b/wpiutil/src/test/native/cpp/span/test_deduction_guides.cpp
new file mode 100644
index 0000000..9851b5e
--- /dev/null
+++ b/wpiutil/src/test/native/cpp/span/test_deduction_guides.cpp
@@ -0,0 +1,98 @@
+
+#include "wpi/span.h"
+
+#include "gtest/gtest.h"
+
+#include <vector>
+
+using wpi::span;
+
+namespace {
+
+template <typename R1, typename R2>
+constexpr bool equal(R1&& r1, R2&& r2)
+{
+ auto first1 = std::begin(r1);
+ const auto last1 = std::end(r1);
+ auto first2 = std::begin(r2);
+ const auto last2 = std::end(r2);
+
+ while (first1 != last1 && first2 != last2) {
+ if (*first1 != *first2) {
+ return false;
+ }
+ ++first1;
+ ++first2;
+ }
+
+ return true;
+}
+
+constexpr bool test_raw_array()
+{
+ int arr[] = {1, 2, 3};
+ auto s = span{arr};
+ static_assert(std::is_same_v<decltype(s), span<int, 3>>);
+
+ return equal(arr, s);
+}
+
+constexpr bool test_const_raw_array()
+{
+ constexpr int arr[] = {1, 2, 3};
+ auto s = span{arr};
+ static_assert(std::is_same_v<decltype(s), span<const int, 3>>);
+
+ return equal(arr, s);
+}
+
+constexpr bool test_std_array()
+{
+ auto arr = std::array<int, 3>{1, 2, 3};
+ auto s = span{arr};
+ static_assert(std::is_same_v<decltype(s), span<int, 3>>);
+
+ return equal(arr, s);
+}
+
+constexpr bool test_const_std_array()
+{
+ const auto arr = std::array<int, 3>{1, 2, 3};
+ auto s = span{arr};
+ static_assert(std::is_same_v<decltype(s), span<const int, 3>>);
+
+ return equal(arr, s);
+}
+
+bool test_vec()
+{
+ auto arr = std::vector{1, 2, 3};
+ auto s = span{arr};
+ static_assert(std::is_same_v<decltype(s), span<int>>);
+
+ return equal(arr, s);
+}
+
+bool test_const_vec()
+{
+ const auto arr = std::vector{1, 2, 3};
+ auto s = span{arr};
+ static_assert(std::is_same_v<decltype(s), span<const int>>);
+
+ return equal(arr, s);
+}
+
+}
+
+TEST(Deduction, FromRawArrays)
+{
+ static_assert(test_raw_array());
+ static_assert(test_const_raw_array());
+ static_assert(test_std_array());
+ static_assert(test_const_std_array());
+
+ ASSERT_TRUE(test_std_array());
+ ASSERT_TRUE(test_const_std_array());
+ ASSERT_TRUE(test_vec());
+ ASSERT_TRUE(test_const_vec());
+}
diff --git a/wpiutil/src/test/native/cpp/span/test_span.cpp b/wpiutil/src/test/native/cpp/span/test_span.cpp
new file mode 100644
index 0000000..7cecfd0
--- /dev/null
+++ b/wpiutil/src/test/native/cpp/span/test_span.cpp
@@ -0,0 +1,663 @@
+
+#include "wpi/span.h"
+
+#include <algorithm>
+#include <cassert>
+#include <deque>
+#include <initializer_list>
+#include <vector>
+
+#include "gtest/gtest.h"
+
+using wpi::span;
+
+struct base {};
+struct derived : base {};
+
+TEST(Span, DefaultConstruction)
+{
+ static_assert(std::is_nothrow_default_constructible<span<int>>::value, "");
+ static_assert(std::is_nothrow_default_constructible<span<int, 0>>::value,
+ "");
+ static_assert(!std::is_default_constructible<span<int, 42>>::value, "");
+
+ //SECTION("dynamic size")
+ {
+ constexpr span<int> s{};
+ static_assert(s.size() == 0, "");
+ static_assert(s.data() == nullptr, "");
+ // This causes an ICE on MSVC
+#ifndef _MSC_VER
+ static_assert(s.begin() == s.end(), "");
+#else
+ ASSERT_EQ(s.begin(), s.end());
+#endif
+ }
+
+ //SECTION("fixed size")
+ {
+ constexpr span<int, 0> s{};
+ static_assert(s.size() == 0, "");
+ static_assert(s.data() == nullptr, "");
+#ifndef _MSC_VER
+ static_assert(s.begin() == s.end(), "");
+#else
+ ASSERT_EQ(s.begin(), s.end());
+#endif
+ }
+}
+
+TEST(Span, PointerLengthConstruction)
+{
+ static_assert(std::is_constructible<span<int>, int*, int>::value, "");
+ static_assert(std::is_constructible<span<const int>, int*, int>::value, "");
+ static_assert(
+ std::is_constructible<span<const int>, const int*, int>::value, "");
+
+ static_assert(std::is_constructible<span<int, 42>, int*, int>::value, "");
+ static_assert(std::is_constructible<span<const int, 42>, int*, int>::value,
+ "");
+ static_assert(
+ std::is_constructible<span<const int, 42>, const int*, int>::value, "");
+
+ //SECTION("dynamic size")
+ {
+ int arr[] = {1, 2, 3};
+ span<int> s(arr, 3);
+
+ ASSERT_EQ(s.size(), 3u);
+ ASSERT_EQ(s.data(), arr);
+ ASSERT_EQ(s.begin(), std::begin(arr));
+ ASSERT_EQ(s.end(), std::end(arr));
+ }
+
+ //SECTION("fixed size")
+ {
+ int arr[] = {1, 2, 3};
+ span<int, 3> s(arr, 3);
+
+ ASSERT_EQ(s.size(), 3u);
+ ASSERT_EQ(s.data(), arr);
+ ASSERT_EQ(s.begin(), std::begin(arr));
+ ASSERT_EQ(s.end(), std::end(arr));
+ }
+}
+
+TEST(Span, PointerPointerConstruction)
+{
+ static_assert(std::is_constructible<span<int>, int*, int*>::value, "");
+ static_assert(!std::is_constructible<span<int>, float*, float*>::value, "");
+ static_assert(std::is_constructible<span<int, 42>, int*, int*>::value, "");
+ static_assert(!std::is_constructible<span<int, 42>, float*, float*>::value,
+ "");
+
+ //SECTION("dynamic size")
+ {
+ int arr[] = {1, 2, 3};
+ span<int> s{arr, arr + 3};
+ ASSERT_EQ(s.size(), 3u);
+ ASSERT_EQ(s.data(), arr);
+ ASSERT_EQ(s.begin(), std::begin(arr));
+ ASSERT_EQ(s.end(), std::end(arr));
+ }
+
+ //SECTION("fixed size")
+ {
+ int arr[] = {1, 2, 3};
+ span<int, 3> s{arr, arr + 3};
+ ASSERT_EQ(s.size(), 3u);
+ ASSERT_EQ(s.data(), arr);
+ ASSERT_EQ(s.begin(), std::begin(arr));
+ ASSERT_EQ(s.end(), std::end(arr));
+ }
+}
+
+TEST(Span, CArrayConstruction)
+{
+ using int_array_t = int[3];
+ using float_array_t = float[3];
+
+ static_assert(std::is_nothrow_constructible<span<int>, int_array_t&>::value,
+ "");
+ static_assert(!std::is_constructible<span<int>, int_array_t const&>::value,
+ "");
+ static_assert(!std::is_constructible<span<int>, float_array_t>::value, "");
+
+ static_assert(
+ std::is_nothrow_constructible<span<const int>, int_array_t&>::value,
+ "");
+ static_assert(std::is_nothrow_constructible<span<const int>,
+ int_array_t const&>::value,
+ "");
+ static_assert(!std::is_constructible<span<const int>, float_array_t>::value,
+ "");
+
+ static_assert(
+ std::is_nothrow_constructible<span<int, 3>, int_array_t&>::value, "");
+ static_assert(
+ !std::is_constructible<span<int, 3>, int_array_t const&>::value, "");
+ static_assert(!std::is_constructible<span<int, 3>, float_array_t&>::value,
+ "");
+
+ static_assert(
+ std::is_nothrow_constructible<span<const int, 3>, int_array_t&>::value,
+ "");
+ static_assert(std::is_nothrow_constructible<span<const int, 3>,
+ int_array_t const&>::value,
+ "");
+ static_assert(
+ !std::is_constructible<span<const int, 3>, float_array_t>::value, "");
+
+ static_assert(!std::is_constructible<span<int, 42>, int_array_t&>::value,
+ "");
+ static_assert(
+ !std::is_constructible<span<int, 42>, int_array_t const&>::value, "");
+ static_assert(!std::is_constructible<span<int, 42>, float_array_t&>::value,
+ "");
+
+ static_assert(
+ !std::is_constructible<span<const int, 42>, int_array_t&>::value, "");
+ static_assert(
+ !std::is_constructible<span<const int, 42>, int_array_t const&>::value,
+ "");
+ static_assert(
+ !std::is_constructible<span<const int, 42>, float_array_t&>::value, "");
+
+ //SECTION("non-const, dynamic size")
+ {
+ int arr[] = {1, 2, 3};
+ span<int> s{arr};
+ ASSERT_EQ(s.size(), 3u);
+ ASSERT_EQ(s.data(), arr);
+ ASSERT_EQ(s.begin(), std::begin(arr));
+ ASSERT_EQ(s.end(), std::end(arr));
+ }
+
+ //SECTION("const, dynamic size")
+ {
+ int arr[] = {1, 2, 3};
+ span<int const> s{arr};
+ ASSERT_EQ(s.size(), 3u);
+ ASSERT_EQ(s.data(), arr);
+ ASSERT_EQ(s.begin(), std::begin(arr));
+ ASSERT_EQ(s.end(), std::end(arr));
+ }
+
+ //SECTION("non-const, static size")
+ {
+ int arr[] = {1, 2, 3};
+ span<int, 3> s{arr};
+ ASSERT_EQ(s.size(), 3u);
+ ASSERT_EQ(s.data(), arr);
+ ASSERT_EQ(s.begin(), std::begin(arr));
+ ASSERT_EQ(s.end(), std::end(arr));
+ }
+
+ //SECTION("const, dynamic size")
+ {
+ int arr[] = {1, 2, 3};
+ span<int const, 3> s{arr};
+ ASSERT_EQ(s.size(), 3u);
+ ASSERT_EQ(s.data(), arr);
+ ASSERT_EQ(s.begin(), std::begin(arr));
+ ASSERT_EQ(s.end(), std::end(arr));
+ }
+}
+
+TEST(Span, StdArrayConstruction)
+{
+ using int_array_t = std::array<int, 3>;
+ using float_array_t = std::array<float, 3>;
+ using zero_array_t = std::array<int, 0>;
+
+ static_assert(std::is_nothrow_constructible<span<int>, int_array_t&>::value,
+ "");
+ static_assert(!std::is_constructible<span<int>, int_array_t const&>::value,
+ "");
+ static_assert(!std::is_constructible<span<int>, float_array_t>::value, "");
+
+ static_assert(
+ std::is_nothrow_constructible<span<const int>, int_array_t&>::value,
+ "");
+ static_assert(std::is_nothrow_constructible<span<const int>,
+ int_array_t const&>::value,
+ "");
+ static_assert(
+ !std::is_constructible<span<const int>, float_array_t const&>::value,
+ "");
+
+ static_assert(
+ std::is_nothrow_constructible<span<int, 3>, int_array_t&>::value, "");
+ static_assert(
+ !std::is_constructible<span<int, 3>, int_array_t const&>::value, "");
+ static_assert(!std::is_constructible<span<int, 3>, float_array_t>::value,
+ "");
+
+ static_assert(
+ std::is_nothrow_constructible<span<const int, 3>, int_array_t&>::value,
+ "");
+ static_assert(std::is_nothrow_constructible<span<const int, 3>,
+ int_array_t const&>::value,
+ "");
+ static_assert(
+ !std::is_constructible<span<const int, 3>, float_array_t const&>::value,
+ "");
+
+ static_assert(!std::is_constructible<span<int, 42>, int_array_t&>::value,
+ "");
+ static_assert(
+ !std::is_constructible<span<int, 42>, int_array_t const&>::value, "");
+ static_assert(
+ !std::is_constructible<span<int, 42>, float_array_t const&>::value, "");
+
+ static_assert(
+ !std::is_constructible<span<const int, 42>, int_array_t&>::value, "");
+ static_assert(
+ !std::is_constructible<span<const int, 42>, int_array_t const&>::value,
+ "");
+ static_assert(
+ !std::is_constructible<span<const int, 42>, float_array_t&>::value, "");
+
+ static_assert(std::is_constructible<span<int>, zero_array_t&>::value, "");
+ static_assert(!std::is_constructible<span<int>, const zero_array_t&>::value,
+ "");
+ static_assert(std::is_constructible<span<const int>, zero_array_t&>::value,
+ "");
+ static_assert(
+ std::is_constructible<span<const int>, const zero_array_t&>::value, "");
+
+ static_assert(std::is_constructible<span<int, 0>, zero_array_t&>::value,
+ "");
+ static_assert(
+ !std::is_constructible<span<int, 0>, const zero_array_t&>::value, "");
+ static_assert(
+ std::is_constructible<span<const int, 0>, zero_array_t&>::value, "");
+ static_assert(
+ std::is_constructible<span<const int, 0>, const zero_array_t&>::value,
+ "");
+
+ //SECTION("non-const, dynamic size")
+ {
+ int_array_t arr = {1, 2, 3};
+ span<int> s{arr};
+ ASSERT_EQ(s.size(), 3u);
+ ASSERT_EQ(s.data(), arr.data());
+ ASSERT_EQ(s.begin(), arr.data());
+ ASSERT_EQ(s.end(), arr.data() + 3);
+ }
+
+ //SECTION("const, dynamic size")
+ {
+ int_array_t arr = {1, 2, 3};
+ span<int const> s{arr};
+ ASSERT_EQ(s.size(), 3u);
+ ASSERT_EQ(s.data(), arr.data());
+ ASSERT_EQ(s.begin(), arr.data());
+ ASSERT_EQ(s.end(), arr.data() + 3);
+ }
+
+ //SECTION("non-const, static size")
+ {
+ int_array_t arr = {1, 2, 3};
+ span<int, 3> s{arr};
+ ASSERT_EQ(s.size(), 3u);
+ ASSERT_EQ(s.data(), arr.data());
+ ASSERT_EQ(s.begin(), arr.data());
+ ASSERT_EQ(s.end(), arr.data() + 3);
+ }
+
+ //SECTION("const, dynamic size")
+ {
+ int_array_t arr = {1, 2, 3};
+ span<int const, 3> s{arr};
+ ASSERT_EQ(s.size(), 3u);
+ ASSERT_EQ(s.data(), arr.data());
+ ASSERT_EQ(s.begin(), arr.data());
+ ASSERT_EQ(s.end(), arr.data() + 3);
+ }
+}
+
+TEST(Span, ConstructionFromOtherContainers)
+{
+ using vec_t = std::vector<int>;
+ using deque_t = std::deque<int>;
+
+ static_assert(std::is_constructible<span<int>, vec_t&>::value, "");
+ static_assert(!std::is_constructible<span<int>, const vec_t&>::value, "");
+ static_assert(!std::is_constructible<span<int>, const deque_t&>::value, "");
+
+ static_assert(std::is_constructible<span<const int>, vec_t&>::value, "");
+ static_assert(std::is_constructible<span<const int>, const vec_t&>::value,
+ "");
+ static_assert(
+ !std::is_constructible<span<const int>, const deque_t&>::value, "");
+
+ static_assert(!std::is_constructible<span<int, 3>, vec_t&>::value, "");
+ static_assert(!std::is_constructible<span<int, 3>, const vec_t&>::value,
+ "");
+ static_assert(!std::is_constructible<span<int, 3>, const deque_t&>::value,
+ "");
+
+ static_assert(!std::is_constructible<span<const int, 3>, vec_t&>::value, "");
+ static_assert(
+ !std::is_constructible<span<const int, 3>, const vec_t&>::value, "");
+ static_assert(
+ !std::is_constructible<span<const int, 3>, const deque_t&>::value, "");
+
+ // vector<bool> is not contiguous and cannot be converted to span<bool>
+ // Regression test for https://github.com/tcbrindle/span/issues/24
+ static_assert(
+ !std::is_constructible<span<bool>, std::vector<bool>&>::value, "");
+ static_assert(!std::is_constructible<span<const bool>,
+ const std::vector<bool>&>::value, "");
+
+ //SECTION("non-const, dynamic size")
+ {
+ vec_t arr = {1, 2, 3};
+ span<int> s{arr};
+ ASSERT_EQ(s.size(), 3u);
+ ASSERT_EQ(s.data(), arr.data());
+ ASSERT_EQ(s.begin(), arr.data());
+ ASSERT_EQ(s.end(), arr.data() + 3);
+ }
+
+ //SECTION("const, dynamic size")
+ {
+ vec_t arr = {1, 2, 3};
+ span<int const> s{arr};
+ ASSERT_EQ(s.size(), 3u);
+ ASSERT_EQ(s.data(), arr.data());
+ ASSERT_EQ(s.begin(), arr.data());
+ ASSERT_EQ(s.end(), arr.data() + 3);
+ }
+
+ //SECTION("non-const, static size")
+ {
+ std::array<int, 3> arr = {1, 2, 3};
+ span<int, 3> s{arr};
+ ASSERT_EQ(s.size(), 3u);
+ ASSERT_EQ(s.data(), arr.data());
+ ASSERT_EQ(s.begin(), arr.data());
+ ASSERT_EQ(s.end(), arr.data() + 3);
+ }
+
+ //SECTION("const, dynamic size")
+ {
+ std::array<int, 3> arr = {1, 2, 3};
+ span<int const, 3> s{arr};
+ ASSERT_EQ(s.size(), 3u);
+ ASSERT_EQ(s.data(), arr.data());
+ ASSERT_EQ(s.begin(), arr.data());
+ ASSERT_EQ(s.end(), arr.data() + 3);
+ }
+}
+
+TEST(Span, ConstructionFromSpansOfDifferentSize)
+{
+ using zero_span = span<int, 0>;
+ using zero_const_span = span<const int, 0>;
+ using big_span = span<int, 1000000>;
+ using big_const_span = span<const int, 1000000>;
+ using dynamic_span = span<int>;
+ using dynamic_const_span = span<const int>;
+
+ static_assert(std::is_trivially_copyable<zero_span>::value, "");
+ static_assert(std::is_trivially_move_constructible<zero_span>::value, "");
+ static_assert(!std::is_constructible<zero_span, zero_const_span>::value,
+ "");
+ static_assert(!std::is_constructible<zero_span, big_span>::value, "");
+ static_assert(!std::is_constructible<zero_span, big_const_span>::value, "");
+ static_assert(!std::is_constructible<zero_span, dynamic_span>::value, "");
+ static_assert(!std::is_constructible<zero_span, dynamic_const_span>::value,
+ "");
+
+ static_assert(
+ std::is_nothrow_constructible<zero_const_span, zero_span>::value, "");
+ static_assert(std::is_trivially_copyable<zero_const_span>::value, "");
+ static_assert(std::is_trivially_move_constructible<zero_const_span>::value,
+ "");
+ static_assert(!std::is_constructible<zero_const_span, big_span>::value, "");
+ static_assert(
+ !std::is_constructible<zero_const_span, big_const_span>::value, "");
+ static_assert(!std::is_constructible<zero_const_span, dynamic_span>::value,
+ "");
+ static_assert(
+ !std::is_constructible<zero_const_span, dynamic_const_span>::value, "");
+
+ static_assert(!std::is_constructible<big_span, zero_span>::value, "");
+ static_assert(!std::is_constructible<big_span, zero_const_span>::value, "");
+ static_assert(std::is_trivially_copyable<big_span>::value, "");
+ static_assert(std::is_trivially_move_constructible<big_span>::value, "");
+ static_assert(!std::is_constructible<big_span, big_const_span>::value, "");
+ static_assert(!std::is_constructible<big_span, dynamic_span>::value, "");
+ static_assert(!std::is_constructible<big_span, dynamic_const_span>::value,
+ "");
+
+ static_assert(!std::is_constructible<big_const_span, zero_span>::value, "");
+ static_assert(
+ !std::is_constructible<big_const_span, zero_const_span>::value, "");
+ static_assert(std::is_trivially_copyable<big_const_span>::value, "");
+ static_assert(std::is_trivially_move_constructible<big_const_span>::value,
+ "");
+ static_assert(
+ std::is_nothrow_constructible<big_const_span, big_span>::value, "");
+ static_assert(!std::is_constructible<big_const_span, dynamic_span>::value,
+ "");
+ static_assert(
+ !std::is_constructible<big_const_span, dynamic_const_span>::value, "");
+
+ static_assert(std::is_nothrow_constructible<dynamic_span, zero_span>::value,
+ "");
+ static_assert(!std::is_constructible<dynamic_span, zero_const_span>::value,
+ "");
+ static_assert(std::is_nothrow_constructible<dynamic_span, big_span>::value,
+ "");
+ static_assert(!std::is_constructible<dynamic_span, big_const_span>::value,
+ "");
+ static_assert(std::is_trivially_copyable<dynamic_span>::value, "");
+ static_assert(std::is_trivially_move_constructible<dynamic_span>::value,
+ "");
+ static_assert(
+ !std::is_constructible<dynamic_span, dynamic_const_span>::value, "");
+
+ static_assert(
+ std::is_nothrow_constructible<dynamic_const_span, zero_span>::value,
+ "");
+ static_assert(std::is_nothrow_constructible<dynamic_const_span,
+ zero_const_span>::value,
+ "");
+ static_assert(
+ std::is_nothrow_constructible<dynamic_const_span, big_span>::value, "");
+ static_assert(std::is_nothrow_constructible<dynamic_const_span,
+ big_const_span>::value,
+ "");
+ static_assert(
+ std::is_nothrow_constructible<dynamic_const_span, dynamic_span>::value,
+ "");
+ static_assert(std::is_trivially_copyable<dynamic_const_span>::value, "");
+ static_assert(
+ std::is_trivially_move_constructible<dynamic_const_span>::value, "");
+
+ constexpr zero_const_span s0{};
+ constexpr dynamic_const_span d{s0};
+
+ static_assert(d.size() == 0, "");
+ static_assert(d.data() == nullptr, "");
+#ifndef _MSC_VER
+ static_assert(d.begin() == d.end(), "");
+#else
+ ASSERT_EQ(d.begin(), d.end());
+#endif
+}
+
+TEST(Span, MemberSubviewOperations)
+{
+ //SECTION("first<N>")
+ {
+ int arr[] = {1, 2, 3, 4, 5};
+ span<int, 5> s{arr};
+ auto f = s.first<3>();
+
+ static_assert(std::is_same<decltype(f), span<int, 3>>::value, "");
+ ASSERT_EQ(f.size(), 3u);
+ ASSERT_EQ(f.data(), arr);
+ ASSERT_EQ(f.begin(), arr);
+ ASSERT_EQ(f.end(), arr + 3);
+ }
+
+ //SECTION("last<N>")
+ {
+ int arr[] = {1, 2, 3, 4, 5};
+ span<int, 5> s{arr};
+ auto l = s.last<3>();
+
+ static_assert(std::is_same<decltype(l), span<int, 3>>::value, "");
+ ASSERT_EQ(l.size(), 3u);
+ ASSERT_EQ(l.data(), arr + 2);
+ ASSERT_EQ(l.begin(), arr + 2);
+ ASSERT_EQ(l.end(), std::end(arr));
+ }
+
+ //SECTION("subspan<N>")
+ {
+ int arr[] = {1, 2, 3, 4, 5};
+ span<int, 5> s{arr};
+ auto ss = s.subspan<1, 2>();
+
+ static_assert(std::is_same<decltype(ss), span<int, 2>>::value, "");
+ ASSERT_EQ(ss.size(), 2u);
+ ASSERT_EQ(ss.data(), arr + 1);
+ ASSERT_EQ(ss.begin(), arr + 1);
+ ASSERT_EQ(ss.end(), arr + 1 + 2);
+ }
+
+ //SECTION("first(n)")
+ {
+ int arr[] = {1, 2, 3, 4, 5};
+ span<int, 5> s{arr};
+ auto f = s.first(3);
+
+ static_assert(std::is_same<decltype(f), span<int>>::value, "");
+ ASSERT_EQ(f.size(), 3u);
+ ASSERT_EQ(f.data(), arr);
+ ASSERT_EQ(f.begin(), arr);
+ ASSERT_EQ(f.end(), arr + 3);
+ }
+
+ //SECTION("last(n)")
+ {
+ int arr[] = {1, 2, 3, 4, 5};
+ span<int, 5> s{arr};
+ auto l = s.last(3);
+
+ static_assert(std::is_same<decltype(l), span<int>>::value, "");
+ ASSERT_EQ(l.size(), 3u);
+ ASSERT_EQ(l.data(), arr + 2);
+ ASSERT_EQ(l.begin(), arr + 2);
+ ASSERT_EQ(l.end(), std::end(arr));
+ }
+
+ //SECTION("subspan(n)")
+ {
+ int arr[] = {1, 2, 3, 4, 5};
+ span<int, 5> s{arr};
+ auto ss = s.subspan(1, 2);
+
+ static_assert(std::is_same<decltype(ss), span<int>>::value, "");
+ ASSERT_EQ(ss.size(), 2u);
+ ASSERT_EQ(ss.data(), arr + 1);
+ ASSERT_EQ(ss.begin(), arr + 1);
+ ASSERT_EQ(ss.end(), arr + 1 + 2);
+ }
+
+ // TODO: Test all the dynamic subspan possibilities
+}
+
+TEST(Span, Observers)
+{
+ // We already use this everywhere, but whatever
+ constexpr span<int, 0> empty{};
+ static_assert(empty.size() == 0, "");
+ static_assert(empty.empty(), "");
+
+ constexpr int arr[] = {1, 2, 3};
+ static_assert(span<const int>{arr}.size() == 3, "");
+ static_assert(!span<const int>{arr}.empty(), "");
+}
+
+TEST(Span, ElementAccess)
+{
+ constexpr int arr[] = {1, 2, 3};
+ span<const int> s{arr};
+
+ ASSERT_EQ(s[0], arr[0]);
+ ASSERT_EQ(s[1], arr[1]);
+ ASSERT_EQ(s[2], arr[2]);
+}
+
+TEST(Span, IteratorSupport)
+{
+ {
+ std::vector<int> vec;
+ span<int> s{vec};
+ std::sort(s.begin(), s.end());
+ ASSERT_TRUE(std::is_sorted(vec.cbegin(), vec.cend()));
+ }
+
+ {
+ const std::vector<int> vec{1, 2, 3};
+ span<const int> s{vec};
+ ASSERT_TRUE(std::equal(s.rbegin(), s.rend(), vec.crbegin()));
+ }
+}
+
+TEST(Span, MakeSpan)
+{
+ {
+ int arr[3] = {1, 2, 3};
+ auto s = wpi::span(arr);
+ static_assert(std::is_same<decltype(s), span<int, 3>>::value, "");
+ ASSERT_EQ(s.data(), arr);
+ ASSERT_EQ(s.size(), 3u);
+ }
+
+ {
+ const int arr[3] = {1, 2, 3};
+ auto s = wpi::span(arr);
+ static_assert(std::is_same<decltype(s), span<const int, 3>>::value, "");
+ ASSERT_EQ(s.data(), arr);
+ ASSERT_EQ(s.size(), 3u);
+ }
+
+ {
+ std::array<int, 3> arr = {1, 2, 3};
+ auto s = wpi::span(arr);
+ static_assert(std::is_same<decltype(s), span<int, 3>>::value, "");
+ ASSERT_EQ(s.data(), arr.data());
+ ASSERT_EQ(s.size(), arr.size());
+ }
+
+ {
+ const std::array<int, 3> arr = {1, 2, 3};
+ auto s = wpi::span(arr);
+ static_assert(std::is_same<decltype(s), span<const int, 3>>::value, "");
+ ASSERT_EQ(s.data(), arr.data());
+ ASSERT_EQ(s.size(), 3u);
+ }
+
+ {
+ std::vector<int> arr = {1, 2, 3};
+ auto s = wpi::span(arr);
+ static_assert(std::is_same<decltype(s), span<int>>::value, "");
+ ASSERT_EQ(s.data(), arr.data());
+ ASSERT_EQ(s.size(), arr.size());
+ }
+
+ {
+ const std::vector<int> arr = {1, 2, 3};
+ auto s = wpi::span(arr);
+ static_assert(std::is_same<decltype(s), span<const int>>::value, "");
+ ASSERT_EQ(s.data(), arr.data());
+ ASSERT_EQ(s.size(), arr.size());
+ }
+}
diff --git a/wpiutil/src/test/native/cpp/span/test_structured_bindings.cpp b/wpiutil/src/test/native/cpp/span/test_structured_bindings.cpp
new file mode 100644
index 0000000..5ce2969
--- /dev/null
+++ b/wpiutil/src/test/native/cpp/span/test_structured_bindings.cpp
@@ -0,0 +1,30 @@
+
+#include "wpi/span.h"
+
+#include "gtest/gtest.h"
+
+using static_span_t = wpi::span<int, 3>;
+using dynamic_span_t = wpi::span<int>;
+
+static_assert(std::tuple_size_v<static_span_t> == static_span_t::extent);
+static_assert(!wpi::detail::is_complete<std::tuple_size<dynamic_span_t>>::value);
+
+TEST(StructuredBindings, Test)
+{
+ // C++, why you no let me do constexpr structured bindings?
+
+ int arr[] = {1, 2, 3};
+
+ auto& [a1, a2, a3] = arr;
+ auto&& [s1, s2, s3] = wpi::span(arr);
+
+ ASSERT_EQ(a1, s1);
+ ASSERT_EQ(a2, s2);
+ ASSERT_EQ(a3, s3);
+
+ a1 = 99;
+ ASSERT_EQ(s1, 99);
+
+ s2 = 100;
+ ASSERT_EQ(a2, 100);
+}
diff --git a/wpiutil/src/test/native/cpp/spinlock_bench.cpp b/wpiutil/src/test/native/cpp/spinlock_bench.cpp
index b36e558..9534837 100644
--- a/wpiutil/src/test/native/cpp/spinlock_bench.cpp
+++ b/wpiutil/src/test/native/cpp/spinlock_bench.cpp
@@ -1,17 +1,14 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "wpi/spinlock.h" // NOLINT(build/include_order)
#include <chrono>
-#include <iostream>
#include <mutex>
#include <thread>
+#include "fmt/core.h"
#include "gtest/gtest.h"
#include "wpi/mutex.h"
@@ -53,9 +50,8 @@
++value;
}
auto stop = high_resolution_clock::now();
- std::cout << "std::mutex sizeof: " << sizeof(std_mutex)
- << " time: " << duration_cast<microseconds>(stop - start).count()
- << " value: " << value << "\n";
+ fmt::print("std::mutex sizeof: {} time: {} value: {}\n", sizeof(std_mutex),
+ duration_cast<microseconds>(stop - start).count(), value);
});
thrb.join();
@@ -68,9 +64,9 @@
++value;
}
auto stop = high_resolution_clock::now();
- std::cout << "std::recursive_mutex sizeof: " << sizeof(std_recursive_mutex)
- << " time: " << duration_cast<microseconds>(stop - start).count()
- << " value: " << value << "\n";
+ fmt::print("std::recursive_mutex sizeof: {} time: {} value: {}\n",
+ sizeof(std_recursive_mutex),
+ duration_cast<microseconds>(stop - start).count(), value);
});
thrb2.join();
@@ -83,9 +79,8 @@
++value;
}
auto stop = high_resolution_clock::now();
- std::cout << "wpi::mutex sizeof: " << sizeof(wpi_mutex)
- << " time: " << duration_cast<microseconds>(stop - start).count()
- << " value: " << value << "\n";
+ fmt::print("wpi::mutex sizeof: {} time: {} value: {}\n", sizeof(wpi_mutex),
+ duration_cast<microseconds>(stop - start).count(), value);
});
thr2.join();
@@ -98,9 +93,9 @@
++value;
}
auto stop = high_resolution_clock::now();
- std::cout << "wpi::recursive_mutex sizeof: " << sizeof(wpi_recursive_mutex)
- << " time: " << duration_cast<microseconds>(stop - start).count()
- << " value: " << value << "\n";
+ fmt::print("wpi::recursive_mutex sizeof: {} time: {} value: {}\n",
+ sizeof(wpi_recursive_mutex),
+ duration_cast<microseconds>(stop - start).count(), value);
});
thr2b.join();
@@ -113,9 +108,8 @@
++value;
}
auto stop = high_resolution_clock::now();
- std::cout << "spinlock sizeof: " << sizeof(spinlock)
- << " time: " << duration_cast<microseconds>(stop - start).count()
- << " value: " << value << "\n";
+ fmt::print("spinlock sizeof: {} time: {} value: {}\n", sizeof(spinlock),
+ duration_cast<microseconds>(stop - start).count(), value);
});
thr3.join();
@@ -128,9 +122,9 @@
++value;
}
auto stop = high_resolution_clock::now();
- std::cout << "recursive_spinlock1 sizeof: " << sizeof(recursive_spinlock1)
- << " time: " << duration_cast<microseconds>(stop - start).count()
- << " value: " << value << "\n";
+ fmt::print("recursive_spinlock1 sizeof: {} time: {} value: {}\n",
+ sizeof(recursive_spinlock1),
+ duration_cast<microseconds>(stop - start).count(), value);
});
thr4.join();
@@ -143,9 +137,9 @@
++value;
}
auto stop = high_resolution_clock::now();
- std::cout << "recursive_spinlock2 sizeof: " << sizeof(recursive_spinlock2)
- << " time: " << duration_cast<microseconds>(stop - start).count()
- << " value: " << value << "\n";
+ fmt::print("recursive_spinlock2 sizeof: {} time: {} value: {}\n",
+ sizeof(recursive_spinlock2),
+ duration_cast<microseconds>(stop - start).count(), value);
});
thr4b.join();
@@ -158,9 +152,9 @@
++value;
}
auto stop = high_resolution_clock::now();
- std::cout << "recursive_spinlock sizeof: " << sizeof(recursive_spinlock)
- << " time: " << duration_cast<microseconds>(stop - start).count()
- << " value: " << value << "\n";
+ fmt::print("recursive_spinlock sizeof: {} time: {} value: {}\n",
+ sizeof(recursive_spinlock),
+ duration_cast<microseconds>(stop - start).count(), value);
});
thr4c.join();
}
diff --git a/wpiutil/src/test/native/cpp/uv/UvAsyncFunctionTest.cpp b/wpiutil/src/test/native/cpp/uv/UvAsyncFunctionTest.cpp
index 132adea..8407935 100644
--- a/wpiutil/src/test/native/cpp/uv/UvAsyncFunctionTest.cpp
+++ b/wpiutil/src/test/native/cpp/uv/UvAsyncFunctionTest.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "wpi/uv/AsyncFunction.h" // NOLINT(build/include_order)
@@ -14,10 +11,9 @@
#include "wpi/uv/Loop.h"
#include "wpi/uv/Prepare.h"
-namespace wpi {
-namespace uv {
+namespace wpi::uv {
-TEST(UvAsyncFunction, Test) {
+TEST(UvAsyncFunctionTest, Basic) {
int prepare_cb_called = 0;
int async_cb_called[2] = {0, 0};
int close_cb_called = 0;
@@ -32,7 +28,9 @@
prepare->error.connect([](Error) { FAIL(); });
prepare->prepare.connect([&] {
- if (prepare_cb_called++) return;
+ if (prepare_cb_called++) {
+ return;
+ }
theThread = std::thread([&] {
auto call0 = async->Call(0);
auto call1 = async->Call(1);
@@ -59,10 +57,12 @@
ASSERT_EQ(async_cb_called[1], 1);
ASSERT_EQ(close_cb_called, 1);
- if (theThread.joinable()) theThread.join();
+ if (theThread.joinable()) {
+ theThread.join();
+ }
}
-TEST(UvAsyncFunction, Ref) {
+TEST(UvAsyncFunctionTest, Ref) {
int prepare_cb_called = 0;
int val = 0;
@@ -73,7 +73,9 @@
auto prepare = Prepare::Create(loop);
prepare->prepare.connect([&] {
- if (prepare_cb_called++) return;
+ if (prepare_cb_called++) {
+ return;
+ }
theThread = std::thread([&] { ASSERT_EQ(async->Call(1, val).get(), 2); });
});
prepare->Start();
@@ -89,10 +91,12 @@
ASSERT_EQ(val, 1);
- if (theThread.joinable()) theThread.join();
+ if (theThread.joinable()) {
+ theThread.join();
+ }
}
-TEST(UvAsyncFunction, Movable) {
+TEST(UvAsyncFunctionTest, Movable) {
int prepare_cb_called = 0;
std::thread theThread;
@@ -103,7 +107,9 @@
auto prepare = Prepare::Create(loop);
prepare->prepare.connect([&] {
- if (prepare_cb_called++) return;
+ if (prepare_cb_called++) {
+ return;
+ }
theThread = std::thread([&] {
auto val = std::make_unique<int>(1);
auto val2 = async->Call(std::move(val)).get();
@@ -122,10 +128,12 @@
loop->Run();
- if (theThread.joinable()) theThread.join();
+ if (theThread.joinable()) {
+ theThread.join();
+ }
}
-TEST(UvAsyncFunction, CallIgnoreResult) {
+TEST(UvAsyncFunctionTest, CallIgnoreResult) {
int prepare_cb_called = 0;
std::thread theThread;
@@ -136,7 +144,9 @@
auto prepare = Prepare::Create(loop);
prepare->prepare.connect([&] {
- if (prepare_cb_called++) return;
+ if (prepare_cb_called++) {
+ return;
+ }
theThread = std::thread([&] { async->Call(std::make_unique<int>(1)); });
});
prepare->Start();
@@ -150,10 +160,12 @@
loop->Run();
- if (theThread.joinable()) theThread.join();
+ if (theThread.joinable()) {
+ theThread.join();
+ }
}
-TEST(UvAsyncFunction, VoidCall) {
+TEST(UvAsyncFunctionTest, VoidCall) {
int prepare_cb_called = 0;
std::thread theThread;
@@ -163,7 +175,9 @@
auto prepare = Prepare::Create(loop);
prepare->prepare.connect([&] {
- if (prepare_cb_called++) return;
+ if (prepare_cb_called++) {
+ return;
+ }
theThread = std::thread([&] { async->Call(); });
});
prepare->Start();
@@ -176,10 +190,12 @@
loop->Run();
- if (theThread.joinable()) theThread.join();
+ if (theThread.joinable()) {
+ theThread.join();
+ }
}
-TEST(UvAsyncFunction, WaitFor) {
+TEST(UvAsyncFunctionTest, WaitFor) {
int prepare_cb_called = 0;
std::thread theThread;
@@ -189,7 +205,9 @@
auto prepare = Prepare::Create(loop);
prepare->prepare.connect([&] {
- if (prepare_cb_called++) return;
+ if (prepare_cb_called++) {
+ return;
+ }
theThread = std::thread([&] {
ASSERT_FALSE(async->Call().wait_for(std::chrono::milliseconds(10)));
});
@@ -205,10 +223,12 @@
loop->Run();
- if (theThread.joinable()) theThread.join();
+ if (theThread.joinable()) {
+ theThread.join();
+ }
}
-TEST(UvAsyncFunction, VoidWaitFor) {
+TEST(UvAsyncFunctionTest, VoidWaitFor) {
int prepare_cb_called = 0;
std::thread theThread;
@@ -218,7 +238,9 @@
auto prepare = Prepare::Create(loop);
prepare->prepare.connect([&] {
- if (prepare_cb_called++) return;
+ if (prepare_cb_called++) {
+ return;
+ }
theThread = std::thread([&] {
ASSERT_FALSE(async->Call().wait_for(std::chrono::milliseconds(10)));
});
@@ -234,8 +256,9 @@
loop->Run();
- if (theThread.joinable()) theThread.join();
+ if (theThread.joinable()) {
+ theThread.join();
+ }
}
-} // namespace uv
-} // namespace wpi
+} // namespace wpi::uv
diff --git a/wpiutil/src/test/native/cpp/uv/UvAsyncTest.cpp b/wpiutil/src/test/native/cpp/uv/UvAsyncTest.cpp
index e18f972..5561f1e 100644
--- a/wpiutil/src/test/native/cpp/uv/UvAsyncTest.cpp
+++ b/wpiutil/src/test/native/cpp/uv/UvAsyncTest.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
*
@@ -37,10 +34,9 @@
#include "wpi/uv/Loop.h"
#include "wpi/uv/Prepare.h"
-namespace wpi {
-namespace uv {
+namespace wpi::uv {
-TEST(UvAsync, Test) {
+TEST(UvAsyncTest, CallbackOnly) {
std::atomic_int async_cb_called{0};
int prepare_cb_called = 0;
int close_cb_called = 0;
@@ -59,7 +55,9 @@
prepare->error.connect([](Error) { FAIL(); });
prepare->closed.connect([&] { close_cb_called++; });
prepare->prepare.connect([&] {
- if (prepare_cb_called++) return;
+ if (prepare_cb_called++) {
+ return;
+ }
theThread = std::thread([&] {
for (;;) {
mutex.lock();
@@ -98,10 +96,12 @@
ASSERT_EQ(async_cb_called, 3);
ASSERT_EQ(close_cb_called, 2);
- if (theThread.joinable()) theThread.join();
+ if (theThread.joinable()) {
+ theThread.join();
+ }
}
-TEST(UvAsync, Data) {
+TEST(UvAsyncTest, Data) {
int prepare_cb_called = 0;
int async_cb_called[2] = {0, 0};
int close_cb_called = 0;
@@ -116,7 +116,9 @@
prepare->error.connect([](Error) { FAIL(); });
prepare->prepare.connect([&] {
- if (prepare_cb_called++) return;
+ if (prepare_cb_called++) {
+ return;
+ }
theThread = std::thread([&] {
async->Send(0, [&](int v) {
ASSERT_EQ(v, 0);
@@ -142,10 +144,12 @@
ASSERT_EQ(async_cb_called[1], 1);
ASSERT_EQ(close_cb_called, 1);
- if (theThread.joinable()) theThread.join();
+ if (theThread.joinable()) {
+ theThread.join();
+ }
}
-TEST(UvAsync, DataRef) {
+TEST(UvAsyncTest, DataRef) {
int prepare_cb_called = 0;
int val = 0;
@@ -156,7 +160,9 @@
auto prepare = Prepare::Create(loop);
prepare->prepare.connect([&] {
- if (prepare_cb_called++) return;
+ if (prepare_cb_called++) {
+ return;
+ }
theThread = std::thread([&] { async->Send(1, val); });
});
prepare->Start();
@@ -171,8 +177,9 @@
ASSERT_EQ(val, 1);
- if (theThread.joinable()) theThread.join();
+ if (theThread.joinable()) {
+ theThread.join();
+ }
}
-} // namespace uv
-} // namespace wpi
+} // namespace wpi::uv
diff --git a/wpiutil/src/test/native/cpp/uv/UvBufferTest.cpp b/wpiutil/src/test/native/cpp/uv/UvBufferTest.cpp
index e837ca9..e262181 100644
--- a/wpiutil/src/test/native/cpp/uv/UvBufferTest.cpp
+++ b/wpiutil/src/test/native/cpp/uv/UvBufferTest.cpp
@@ -1,50 +1,48 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "wpi/uv/Buffer.h" // NOLINT(build/include_order)
#include "gtest/gtest.h" // NOLINT(build/include_order)
-namespace wpi {
-namespace uv {
+namespace wpi::uv {
-TEST(UvSimpleBufferPool, ConstructDefault) {
+TEST(UvSimpleBufferPoolTest, ConstructDefault) {
SimpleBufferPool<> pool;
auto buf1 = pool.Allocate();
- ASSERT_EQ(buf1.len, 4096u);
+ ASSERT_EQ(buf1.len, 4096u); // NOLINT
+ pool.Release({&buf1, 1});
}
-TEST(UvSimpleBufferPool, ConstructSize) {
+TEST(UvSimpleBufferPoolTest, ConstructSize) {
SimpleBufferPool<4> pool{8192};
auto buf1 = pool.Allocate();
- ASSERT_EQ(buf1.len, 8192u);
+ ASSERT_EQ(buf1.len, 8192u); // NOLINT
+ pool.Release({&buf1, 1});
}
-TEST(UvSimpleBufferPool, ReleaseReuse) {
+TEST(UvSimpleBufferPoolTest, ReleaseReuse) {
SimpleBufferPool<4> pool;
auto buf1 = pool.Allocate();
auto buf1copy = buf1;
auto origSize = buf1.len;
buf1.len = 8;
- pool.Release(buf1);
+ pool.Release({&buf1, 1});
ASSERT_EQ(buf1.base, nullptr);
auto buf2 = pool.Allocate();
ASSERT_EQ(buf1copy.base, buf2.base);
ASSERT_EQ(buf2.len, origSize);
+ pool.Release({&buf2, 1});
}
-TEST(UvSimpleBufferPool, ClearRemaining) {
+TEST(UvSimpleBufferPoolTest, ClearRemaining) {
SimpleBufferPool<4> pool;
auto buf1 = pool.Allocate();
- pool.Release(buf1);
+ pool.Release({&buf1, 1});
ASSERT_EQ(pool.Remaining(), 1u);
pool.Clear();
ASSERT_EQ(pool.Remaining(), 0u);
}
-} // namespace uv
-} // namespace wpi
+} // namespace wpi::uv
diff --git a/wpiutil/src/test/native/cpp/uv/UvGetAddrInfoTest.cpp b/wpiutil/src/test/native/cpp/uv/UvGetAddrInfoTest.cpp
index 20d27f1..b397e24 100644
--- a/wpiutil/src/test/native/cpp/uv/UvGetAddrInfoTest.cpp
+++ b/wpiutil/src/test/native/cpp/uv/UvGetAddrInfoTest.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
*
@@ -34,10 +31,9 @@
#define CONCURRENT_COUNT 10
-namespace wpi {
-namespace uv {
+namespace wpi::uv {
-TEST(UvGetAddrInfo, BothNull) {
+TEST(UvGetAddrInfoTest, BothNull) {
int fail_cb_called = 0;
auto loop = Loop::Create();
@@ -47,12 +43,12 @@
});
GetAddrInfo(
- loop, [](const addrinfo&) { FAIL(); }, Twine::createNull());
+ loop, [](const addrinfo&) { FAIL(); }, "");
loop->Run();
ASSERT_EQ(fail_cb_called, 1);
}
-TEST(UvGetAddrInfo, FailedLookup) {
+TEST(UvGetAddrInfoTest, FailedLookup) {
int fail_cb_called = 0;
auto loop = Loop::Create();
@@ -69,7 +65,7 @@
ASSERT_EQ(fail_cb_called, 1);
}
-TEST(UvGetAddrInfo, Basic) {
+TEST(UvGetAddrInfoTest, Basic) {
int getaddrinfo_cbs = 0;
auto loop = Loop::Create();
@@ -84,7 +80,7 @@
}
#ifndef _WIN32
-TEST(UvGetAddrInfo, Concurrent) {
+TEST(UvGetAddrInfoTest, Concurrent) {
int getaddrinfo_cbs = 0;
int callback_counts[CONCURRENT_COUNT];
@@ -110,5 +106,4 @@
}
#endif
-} // namespace uv
-} // namespace wpi
+} // namespace wpi::uv
diff --git a/wpiutil/src/test/native/cpp/uv/UvGetNameInfoTest.cpp b/wpiutil/src/test/native/cpp/uv/UvGetNameInfoTest.cpp
index 76d22d9..db1eefe 100644
--- a/wpiutil/src/test/native/cpp/uv/UvGetNameInfoTest.cpp
+++ b/wpiutil/src/test/native/cpp/uv/UvGetNameInfoTest.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2020 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
*
@@ -32,10 +29,9 @@
#include "wpi/uv/Loop.h"
-namespace wpi {
-namespace uv {
+namespace wpi::uv {
-TEST(UvGetNameInfo, BasicIp4) {
+TEST(UvGetNameInfoTest, BasicIp4) {
int getnameinfo_cbs = 0;
auto loop = Loop::Create();
@@ -55,7 +51,7 @@
ASSERT_EQ(getnameinfo_cbs, 1);
}
-TEST(UvGetNameInfo, BasicIp6) {
+TEST(UvGetNameInfoTest, BasicIp6) {
int getnameinfo_cbs = 0;
auto loop = Loop::Create();
@@ -75,5 +71,4 @@
ASSERT_EQ(getnameinfo_cbs, 1);
}
-} // namespace uv
-} // namespace wpi
+} // namespace wpi::uv
diff --git a/wpiutil/src/test/native/cpp/uv/UvLoopWalkTest.cpp b/wpiutil/src/test/native/cpp/uv/UvLoopWalkTest.cpp
index 5d2e120..38a3342 100644
--- a/wpiutil/src/test/native/cpp/uv/UvLoopWalkTest.cpp
+++ b/wpiutil/src/test/native/cpp/uv/UvLoopWalkTest.cpp
@@ -1,9 +1,6 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
*
@@ -32,10 +29,9 @@
#include "wpi/uv/Timer.h"
-namespace wpi {
-namespace uv {
+namespace wpi::uv {
-TEST(UvLoop, Walk) {
+TEST(UvLoopTest, Walk) {
int seen_timer_handle = 0;
auto loop = Loop::Create();
@@ -47,7 +43,9 @@
timer->timeout.connect([&, theTimer = timer.get()] {
theTimer->GetLoopRef().Walk([&](Handle& it) {
- if (&it == timer.get()) seen_timer_handle++;
+ if (&it == timer.get()) {
+ seen_timer_handle++;
+ }
});
theTimer->Close();
});
@@ -61,10 +59,11 @@
// Loop is finished, should not see our timer handle
seen_timer_handle = 0;
loop->Walk([&](Handle& it) {
- if (&it == timer.get()) seen_timer_handle++;
+ if (&it == timer.get()) {
+ seen_timer_handle++;
+ }
});
ASSERT_EQ(seen_timer_handle, 0);
}
-} // namespace uv
-} // namespace wpi
+} // namespace wpi::uv
diff --git a/wpiutil/src/test/native/cpp/uv/UvTimerTest.cpp b/wpiutil/src/test/native/cpp/uv/UvTimerTest.cpp
index 6e1bd5c..1a6258f 100644
--- a/wpiutil/src/test/native/cpp/uv/UvTimerTest.cpp
+++ b/wpiutil/src/test/native/cpp/uv/UvTimerTest.cpp
@@ -1,18 +1,14 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2018-2019 FIRST. All Rights Reserved. */
-/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in the root directory of */
-/* the project. */
-/*----------------------------------------------------------------------------*/
+// Copyright (c) FIRST and other WPILib contributors.
+// Open Source Software; you can modify and/or share it under the terms of
+// the WPILib BSD license file in the root directory of this project.
#include "wpi/uv/Timer.h" // NOLINT(build/include_order)
#include "gtest/gtest.h"
-namespace wpi {
-namespace uv {
+namespace wpi::uv {
-TEST(UvTimer, StartAndStop) {
+TEST(UvTimerTest, StartAndStop) {
auto loop = Loop::Create();
auto handleNoRepeat = Timer::Create(loop);
auto handleRepeat = Timer::Create(loop);
@@ -59,7 +55,7 @@
ASSERT_TRUE(checkTimerRepeatEvent);
}
-TEST(UvTimer, Repeat) {
+TEST(UvTimerTest, Repeat) {
auto loop = Loop::Create();
auto handle = Timer::Create(loop);
@@ -70,5 +66,4 @@
loop->Run(); // forces close callback to run
}
-} // namespace uv
-} // namespace wpi
+} // namespace wpi::uv