├── .gitignore ├── LICENSE ├── Makefile ├── README.md ├── docs ├── help └── version ├── includes └── libtest.h ├── resources ├── 000010.gif ├── 42.gif ├── discord.gif ├── example.gif ├── le_xav.jpg ├── logo1.gif ├── logo2.gif ├── title.png └── xav.gif ├── scripts ├── check_files.sh ├── check_hostname.sh ├── check_norminette_version.sh ├── check_sysfunc.sh ├── show_func.sh └── title.sh └── srcs ├── ft_call_test.c ├── global └── globals.c ├── main.c ├── tests ├── ft_test_ascii.c ├── ft_test_atoi.c ├── ft_test_bzero.c ├── ft_test_calloc.c ├── ft_test_itoa.c ├── ft_test_lstadd_back.c ├── ft_test_lstadd_front.c ├── ft_test_lstclear.c ├── ft_test_lstdelone.c ├── ft_test_lstiter.c ├── ft_test_lstlast.c ├── ft_test_lstmap.c ├── ft_test_lstnew.c ├── ft_test_lstsize.c ├── ft_test_memchr.c ├── ft_test_memcmp.c ├── ft_test_memcpy.c ├── ft_test_memmove.c ├── ft_test_memset.c ├── ft_test_putchar_fd.c ├── ft_test_putendl_fd.c ├── ft_test_putnbr_fd.c ├── ft_test_putstr_fd.c ├── ft_test_split.c ├── ft_test_strchr.c ├── ft_test_strdup.c ├── ft_test_striteri.c ├── ft_test_strjoin.c ├── ft_test_strlcat.c ├── ft_test_strlcpy.c ├── ft_test_strlen.c ├── ft_test_strmapi.c ├── ft_test_strncmp.c ├── ft_test_strnstr.c ├── ft_test_strrchr.c ├── ft_test_strtrim.c └── ft_test_substr.c └── utils ├── ft_print_test.c └── ft_utils.c /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Object files 5 | *.o 6 | *.ko 7 | *.obj 8 | *.elf 9 | 10 | # Linker output 11 | *.ilk 12 | *.map 13 | *.exp 14 | 15 | # Precompiled Headers 16 | *.gch 17 | *.pch 18 | 19 | # Libraries 20 | *.lib 21 | *.a 22 | *.la 23 | *.lo 24 | 25 | # Shared objects (inc. Windows DLLs) 26 | *.dll 27 | *.so 28 | *.so.* 29 | *.dylib 30 | 31 | # Executables 32 | *.exe 33 | *.out 34 | *.app 35 | *.i*86 36 | *.x86_64 37 | *.hex 38 | 39 | # Debug files 40 | *.dSYM/ 41 | *.su 42 | *.idb 43 | *.pdb 44 | 45 | # Kernel Module Compile Results 46 | *.mod* 47 | *.cmd 48 | .tmp_versions/ 49 | modules.order 50 | Module.symvers 51 | Mkfile.old 52 | dkms.conf 53 | 54 | # Vim 55 | *.swp 56 | 57 | # Program 58 | libtest 59 | 60 | # vscode 61 | .vscode/ -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | SRC_DIR = ./srcs/ 2 | INC_DIR = ./includes/ 3 | 4 | SRC = main.c \ 5 | global/globals.c \ 6 | ft_call_test.c \ 7 | utils/ft_utils.c \ 8 | utils/ft_print_test.c \ 9 | tests/ft_test_ascii.c \ 10 | tests/ft_test_strlen.c \ 11 | tests/ft_test_memset.c \ 12 | tests/ft_test_bzero.c \ 13 | tests/ft_test_memcpy.c \ 14 | tests/ft_test_memmove.c \ 15 | tests/ft_test_strlcpy.c \ 16 | tests/ft_test_strlcat.c \ 17 | tests/ft_test_strchr.c \ 18 | tests/ft_test_strrchr.c \ 19 | tests/ft_test_strncmp.c \ 20 | tests/ft_test_memchr.c \ 21 | tests/ft_test_memcmp.c \ 22 | tests/ft_test_strnstr.c \ 23 | tests/ft_test_atoi.c \ 24 | tests/ft_test_calloc.c \ 25 | tests/ft_test_strdup.c \ 26 | tests/ft_test_substr.c \ 27 | tests/ft_test_strjoin.c \ 28 | tests/ft_test_strtrim.c \ 29 | tests/ft_test_split.c \ 30 | tests/ft_test_itoa.c \ 31 | tests/ft_test_strmapi.c \ 32 | tests/ft_test_striteri.c \ 33 | tests/ft_test_putchar_fd.c \ 34 | tests/ft_test_putstr_fd.c \ 35 | tests/ft_test_putendl_fd.c \ 36 | tests/ft_test_putnbr_fd.c \ 37 | 38 | SRC_BONUS = tests/ft_test_lstnew.c \ 39 | tests/ft_test_lstadd_front.c \ 40 | tests/ft_test_lstsize.c \ 41 | tests/ft_test_lstlast.c \ 42 | tests/ft_test_lstadd_back.c \ 43 | tests/ft_test_lstdelone.c \ 44 | tests/ft_test_lstclear.c \ 45 | tests/ft_test_lstiter.c \ 46 | tests/ft_test_lstmap.c 47 | 48 | SRCS = $(addprefix $(SRC_DIR), $(SRC)) 49 | SRCS_BONUS = ${addprefix ${SRC_DIR}, ${SRC_BONUS}} 50 | 51 | OBJS = $(SRCS:.c=.o) 52 | OBJS_BONUS = ${SRCS_BONUS:.c=.o} 53 | 54 | CC = cc 55 | CFLAGS = -g -Wall -Wextra -Werror -fsanitize=address -fsanitize=undefined 56 | LFLAGS = -lbsd 57 | RM = rm -f 58 | 59 | NAME = libtest 60 | 61 | G = \e[92m 62 | X = \e[0m 63 | BAR_SIZE = 50 64 | 65 | TOTAL_FILES := $(words $(SRC)) 66 | COMPILED_FILES := 0 67 | 68 | CHECK_SCRIPT = ./scripts/check_files.sh 69 | CHECK_BONUS = ./scripts/check_files.sh bonus 70 | 71 | 72 | all: $(NAME) 73 | 74 | .c.o: 75 | @$(CC) $(CFLAGS) -c -I $(INC_DIR) $< -o $(<:.c=.o) 76 | @$(eval COMPILED_FILES := $(shell echo $$(($(COMPILED_FILES)+1)))) 77 | @echo -n "[" 78 | @for i in `seq 1 $(shell echo "$$(($(COMPILED_FILES)*$(BAR_SIZE)/$(TOTAL_FILES)))")`; do \ 79 | echo -n "$(G)▰$(X)" ; \ 80 | done 81 | @for i in `seq 1 $(shell echo "$$(($(BAR_SIZE)-$(COMPILED_FILES)*$(BAR_SIZE)/$(TOTAL_FILES)))")`; do \ 82 | echo -n "▱" ; \ 83 | done 84 | @echo -n "] ($(shell echo "scale=2; $(COMPILED_FILES)/$(TOTAL_FILES) * 100" | bc)%) " 85 | @echo -n "[" 86 | @printf "%d/%d" $(COMPILED_FILES) $(TOTAL_FILES) 87 | @echo -n "] " 88 | @printf "%s" $(notdir $<) 89 | @printf "\e[0K\r" 90 | 91 | $(NAME): mandatory 92 | @clear 93 | @echo "Compilation completed." 94 | 95 | mandatory: title check $(OBJS) 96 | @make -sC .. 97 | @$(CC) $(CFLAGS) -o $(NAME) $(OBJS) $(LFLAGS) ../libft.a 98 | @clear 99 | @echo "Mandatories successfully compiled." 100 | 101 | bonus: title check_bonus $(OBJS) $(OBJS_BONUS) 102 | @make bonus -sC .. 103 | @$(CC) $(CFLAGS) -o $(NAME) $(OBJS) $(OBJS_BONUS) $(LFLAGS) ../libft.a 104 | @clear 105 | @echo "Mandatories & Bonus successfully compiled." 106 | 107 | ncmandatory: title $(OBJS) 108 | @make -sC .. 109 | @$(CC) $(CFLAGS) -o $(NAME) $(OBJS) $(LFLAGS) ../libft.a 110 | @clear 111 | @echo "Mandatories successfully compiled without check." 112 | 113 | ncbonus: title $(OBJS) $(OBJS_BONUS) 114 | @make bonus -sC .. 115 | @$(CC) $(CFLAGS) -o $(NAME) $(OBJS) $(OBJS_BONUS) $(LFLAGS) ../libft.a 116 | @clear 117 | @echo "Mandatories & Bonus successfully compiled without check." 118 | 119 | clean: 120 | @make clean -sC .. 121 | @$(RM) $(OBJS) $(OBJS_BONUS) 122 | @clear 123 | @echo "Clean completed." 124 | 125 | fclean: clean 126 | @printf "\e[1A\e[0K\r" 127 | @make fclean -sC .. 128 | @$(RM) $(NAME) 129 | @clear 130 | @echo "Full clean completed." 131 | 132 | re: fclean all 133 | @clear 134 | @echo "Recompilation completed." 135 | 136 | title: 137 | @scripts/title.sh 138 | @printf "\n" 139 | 140 | check: 141 | @if ! $(CHECK_SCRIPT); then \ 142 | exit 1; \ 143 | fi 144 | 145 | check_bonus: 146 | @if ! $(CHECK_BONUS); then \ 147 | exit 1; \ 148 | fi 149 | 150 | .PHONY: all mandatory bonus ncmandatory ncbonus clean fclean re title check check_bonus 151 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 |
4 | 5 | 6 | 7 | 8 | 9 |

10 | 11 | 12 | libtest is a command-line utility designed to test the functions provided in the libft library. 13 | It includes options to test mandatory and bonus functions, display available functions, and provide version information. 14 | 15 | ## Features 16 | - Check if the Makefile and libft.h exists 17 | - Check Makefile targets 18 | - Check compilation flags 19 | - Check norme errors 20 | - Check forbidden functions 21 | - Check memory leaks 22 | 23 | ## Installation 24 | - Ensure you have a Makefile in your libft containing the targets `all`, `re`, `bonus`, `clean`, and `fclean`. 25 | - Clone the repository into your libft folder using the following command: 26 | ```bash 27 | git clone git@github.com:FonWasH/libtest.git 28 | ``` 29 | Make sure your environment is properly configured before proceeding with the installation steps. 30 | 31 | ## Dependencies 32 | - Norminette https://github.com/42School/norminette 33 | - bc > `sudo apt install bc` 34 | - libbsd > `sudo apt install libbsd-dev` 35 | 36 | ## Make 37 | ```bash 38 | make all # Compile mandatory functions with checks 39 | make libtest # Compile mandatory functions with checks 40 | make mandatory # Compile mandatory functions with checks 41 | make bonus # Compile bonus and mandatory functions with checks 42 | make ncmandatory # Compile mandatory functions without check 43 | make ncbonus # Compile bonus and mandatory functions without check 44 | make check # Run checks on the mandatory functions 45 | make check_bonus # Run checks on the bonus functions 46 | make clean # Remove object files 47 | make fclean # Remove all files 48 | make re # Clean and Re-compile all the files 49 | ``` 50 | 51 | ## Usage 52 | ```bash 53 | libtest [OPTION/FUNCTION]... 54 | 55 | -a, --all # test all functions 56 | -f, --force # test all functions without norme and forbidden functions check 57 | -m, --mandatory # test mandatory functions 58 | -b, --bonus # test bonus functions 59 | -s, --show # display all available functions 60 | -h, --help # display help and exit 61 | -v, --version # output version information and exit 62 | ``` 63 | 64 | ## Examples 65 | - `./libtest ft_atoi` Test the ft_atoi function. 66 | - `./libtest -m` Test all mandatory functions. 67 |

68 | 69 |

-------------------------------------------------------------------------------- /docs/help: -------------------------------------------------------------------------------- 1 | Usage: libtest [OPTION/FUNCTION]... 2 | libtest is a command-line utility designed to test the functions provided in the libft library. 3 | 4 | -a, --all test all functions 5 | -f, --force test all functions without norme and forbidden functions check 6 | -m, --mandatory test mandatory functions 7 | -b, --bonus test bonus functions 8 | -s, --show display all available functions 9 | -h, --help display this help and exit 10 | -v, --version output version information and exit 11 | 12 | Examples: 13 | libtest ft_atoi Test the ft_atoi. 14 | libtest -m Test all mandatory functions. 15 | 16 | Copyright © 2024 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later . 17 | This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. 18 | Written by Julien Perez a.k.a. FonWasH. 19 | -------------------------------------------------------------------------------- /docs/version: -------------------------------------------------------------------------------- 1 | libtest 1.0.0-2024 2 | Copyright (C) 2024 Free Software Foundation, Inc. 3 | License GPLv3+: GNU GPL version 3 or later . 4 | This is free software: you are free to change and redistribute it. 5 | There is NO WARRANTY, to the extent permitted by law. 6 | 7 | Written by Julien Perez a.k.a. FonWasH. 8 | -------------------------------------------------------------------------------- /includes/libtest.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* libtest.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: juperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2024/03/15 08:17:48 by juperez #+# #+# */ 9 | /* Updated: 2024/05/22 15:45:26 by juperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef LIBTEST_H 14 | # define LIBTEST_H 15 | 16 | // LIB 17 | # include "../../libft.h" 18 | # include 19 | # include 20 | # include 21 | # include 22 | # include 23 | # include 24 | # include 25 | # include 26 | # include 27 | # include 28 | # include 29 | # include 30 | 31 | // BUFFER 32 | # define BUFFER_SIZE 1024 33 | 34 | // COLOR 35 | # define R "\e[91m" 36 | # define G "\e[92m" 37 | # define B "\e[94m" 38 | # define Y "\e[33m" 39 | # define BD "\e[1m" 40 | # define DM "\e[2m\e[3m" 41 | # define X "\e[0m" 42 | 43 | // STRING 44 | # define KO R "KO\n" X 45 | # define OK G "OK\n" X 46 | # define CHEAT R "CHEAT\n" X 47 | # define ERROR R "ERROR\n" X 48 | # define GRADE_CHEAT R "-42\n" X 49 | # define FAIL R "FAIL" X " :(\n" 50 | # define SUCCESS G "SUCCESS" X " :)\n" 51 | # define NORME BD "Norminette: " X 52 | # define FOR_FUNC BD "Forbidden Functions: " X 53 | # define TEST BD "Test: " X 54 | # define TIME BD "Time: " X 55 | # define GRADE BD "Grade: " X 56 | # define INPUT BD "\tinput:\t" X "=> " 57 | # define OUTPUT BD "\toutput:\t" X "=> " 58 | # define USER "user: " 59 | # define LIBC "libc: " 60 | # define EXPECT "expected: " 61 | # define MEM DM "\t\t Fail when destination is " 62 | # define HIG "higher\n" X 63 | # define LOW "lower\n" X 64 | # define EQU "equal\n" X 65 | # define LST_SIZE DM "\t\t Wrong list size\n" X 66 | # define LST_FREE DM "\t\t Node not freed\n" X 67 | # define ERROR_HELP "\nTry '--help' for more information.\n" 68 | # define ERROR_MEM "Error: Memory allocation\n" 69 | # define LINE "--------------------------------------" 70 | # define SIZE_LINE 40 71 | 72 | // CMD 73 | # define CMD_NS "norminette -o ../" 74 | # define CMD_NE ".c > /dev/null 2>&1" 75 | # define CMD_NV "./scripts/check_norminette_version.sh" 76 | # define CMD_CS "./scripts/check_sysfunc.sh ../" 77 | # define CMD_CE ".o > /dev/null 2>&1" 78 | 79 | // PATH 80 | # define TITLE "./scripts/title.sh" 81 | # define SHOW_FUNC "./scripts/show_func.sh" 82 | # define SHOW_HELP "docs/help" 83 | # define SHOW_VERSION "docs/version" 84 | 85 | // STRUCT 86 | typedef struct s_ftest 87 | { 88 | char *name; 89 | bool (*f)(char *); 90 | } t_ftest; 91 | 92 | typedef struct s_fascii 93 | { 94 | char *name; 95 | int (*user)(int); 96 | int (*libc)(int); 97 | } t_fascii; 98 | 99 | typedef struct s_result 100 | { 101 | int input_int; 102 | size_t input_sizet; 103 | char input_chr; 104 | char *input_str1; 105 | char *input_str2; 106 | int user_int; 107 | int libc_int; 108 | size_t user_sizet; 109 | size_t libc_sizet; 110 | char user_chr; 111 | char libc_chr; 112 | char *user_str; 113 | char *libc_str; 114 | char **user_tabstr; 115 | char **libc_tabstr; 116 | } t_result; 117 | 118 | typedef struct s_presult 119 | { 120 | bool input_int; 121 | bool input_sizet; 122 | bool input_chr; 123 | bool input_str1; 124 | bool input_str2; 125 | bool output_int; 126 | bool output_sizet; 127 | bool output_chr; 128 | bool output_str; 129 | bool output_tabstr; 130 | } t_presult; 131 | 132 | // ENUM 133 | typedef enum e_ftime 134 | { 135 | RESET, 136 | USER_START, 137 | USER_END, 138 | USER_END_LIBC_START, 139 | LIBC_START, 140 | LIBC_END, 141 | PRINT 142 | } t_ftime; 143 | 144 | // GLOBALS 145 | extern t_presult g_presult; 146 | extern t_result g_result; 147 | extern int g_node_freed; 148 | extern const t_ftest g_fmandatory[]; 149 | extern const t_ftest g_fbonus[]; 150 | extern const char *g_str1_tests[]; 151 | extern const char *g_str2_tests[]; 152 | extern const char *g_nbr_tests[]; 153 | extern const char *g_sortn_tests[]; 154 | extern const char *g_revn_tests[]; 155 | extern const char *g_lowa_tests[]; 156 | extern const char *g_uppa_tests[]; 157 | 158 | // UTIL FUNCTIONS 159 | void ft_print_name(char *name); 160 | void ft_print_file(char *path); 161 | bool ft_test_norminette(char *name); 162 | bool ft_check_sysfunc(char *name); 163 | void ft_time_function(t_ftime action); 164 | void ft_print_result(bool print_libc); 165 | void ft_reset_presult(void); 166 | void ft_result_input_int(int intput); 167 | void ft_result_input_sizet(size_t intput); 168 | void ft_result_input_chr(char intput); 169 | void ft_result_input_str(char *str1, char *str2); 170 | void ft_result_output_int(int user, int libc); 171 | void ft_result_output_sizet(size_t user, size_t libc); 172 | void ft_result_output_chr(char user, char libc); 173 | void ft_result_output_str(char *user, char *libc); 174 | void ft_result_output_tabstr(char **user, char **libc); 175 | void ft_grade(bool success); 176 | void ft_free_lst(t_list *lst); 177 | size_t ft_lst_size(t_list *lst); 178 | void ft_test_free(void *ptr); 179 | void ft_strtoupper(void *ptr); 180 | void *ft_duptoupper(void *ptr); 181 | // MAIN FUNCTIONS 182 | bool ft_call_test(char *name); 183 | void ft_call_all_test(bool title, bool force, const t_ftest *ftest); 184 | // TEST FUNCTIONS 185 | bool ft_test_ascii(char *name); 186 | bool ft_test_strlen(char *name); 187 | bool ft_test_memset(char *name); 188 | bool ft_test_bzero(char *name); 189 | bool ft_test_memcpy(char *name); 190 | bool ft_test_memmove(char *name); 191 | bool ft_test_strlcpy(char *name); 192 | bool ft_test_strlcat(char *name); 193 | bool ft_test_strchr(char *name); 194 | bool ft_test_strrchr(char *name); 195 | bool ft_test_strncmp(char *name); 196 | bool ft_test_memchr(char *name); 197 | bool ft_test_memcmp(char *name); 198 | bool ft_test_strnstr(char *name); 199 | bool ft_test_atoi(char *name); 200 | bool ft_test_calloc(char *name); 201 | bool ft_test_strdup(char *name); 202 | bool ft_test_substr(char *name); 203 | bool ft_test_strjoin(char *name); 204 | bool ft_test_strtrim(char *name); 205 | bool ft_test_split(char *name); 206 | bool ft_test_itoa(char *name); 207 | bool ft_test_strmapi(char *name); 208 | bool ft_test_striteri(char *name); 209 | bool ft_test_putchar_fd(char *name); 210 | bool ft_test_putstr_fd(char *name); 211 | bool ft_test_putendl_fd(char *name); 212 | bool ft_test_putnbr_fd(char *name); 213 | // TEST BONUS FUNCTIONS 214 | bool ft_test_lstnew(char *name) __attribute__((weak)); 215 | bool ft_test_lstadd_front(char *name) __attribute__((weak)); 216 | bool ft_test_lstsize(char *name) __attribute__((weak)); 217 | bool ft_test_lstlast(char *name) __attribute__((weak)); 218 | bool ft_test_lstadd_back(char *name) __attribute__((weak)); 219 | bool ft_test_lstdelone(char *name) __attribute__((weak)); 220 | bool ft_test_lstclear(char *name) __attribute__((weak)); 221 | bool ft_test_lstiter(char *name) __attribute__((weak)); 222 | bool ft_test_lstmap(char *name) __attribute__((weak)); 223 | 224 | #endif 225 | -------------------------------------------------------------------------------- /resources/000010.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FonWasH/libtest/3380d4cc67fd74799194567fdbeffdea2c95f0a8/resources/000010.gif -------------------------------------------------------------------------------- /resources/42.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FonWasH/libtest/3380d4cc67fd74799194567fdbeffdea2c95f0a8/resources/42.gif -------------------------------------------------------------------------------- /resources/discord.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FonWasH/libtest/3380d4cc67fd74799194567fdbeffdea2c95f0a8/resources/discord.gif -------------------------------------------------------------------------------- /resources/example.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FonWasH/libtest/3380d4cc67fd74799194567fdbeffdea2c95f0a8/resources/example.gif -------------------------------------------------------------------------------- /resources/le_xav.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FonWasH/libtest/3380d4cc67fd74799194567fdbeffdea2c95f0a8/resources/le_xav.jpg -------------------------------------------------------------------------------- /resources/logo1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FonWasH/libtest/3380d4cc67fd74799194567fdbeffdea2c95f0a8/resources/logo1.gif -------------------------------------------------------------------------------- /resources/logo2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FonWasH/libtest/3380d4cc67fd74799194567fdbeffdea2c95f0a8/resources/logo2.gif -------------------------------------------------------------------------------- /resources/title.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FonWasH/libtest/3380d4cc67fd74799194567fdbeffdea2c95f0a8/resources/title.png -------------------------------------------------------------------------------- /resources/xav.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FonWasH/libtest/3380d4cc67fd74799194567fdbeffdea2c95f0a8/resources/xav.gif -------------------------------------------------------------------------------- /scripts/check_files.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | R="\e[91m" 4 | G="\e[92m" 5 | Y="\e[93m" 6 | BD="\e[1m" 7 | DM="\e[2m\e[3m" 8 | X="\e[0m" 9 | 10 | dir="../" 11 | files=("libft.h" "Makefile") 12 | targets=("all" "libft.a" "clean" "fclean" "re") 13 | flags=("-Wall" "-Wextra" "-Werror") 14 | 15 | check_lib_norme() { 16 | if [[ $(./scripts/check_norminette_version.sh) -eq 0 ]]; then 17 | if ! norminette -R CheckDefine ../libft.h > /dev/null 2>&1; then 18 | echo -e "${BD}Norminette libft:${X} ${R}ERROR${X}\n" 19 | read -n 1 -s -r -p "Press any key to continue..." 20 | return 1 21 | else 22 | echo -e "${BD}Norminette libft:${X} ${G}OK${X}\n" 23 | read -n 1 -s -r -p "Press any key to continue..." 24 | return 0 25 | fi 26 | else 27 | if norminette -R CheckDefine ../libft.h > /dev/null 2>&1; then 28 | echo -e "${BD}Norminette libft:${X} ${R}ERROR${X}\n" 29 | read -n 1 -s -r -p "Press any key to continue..." 30 | return 1 31 | else 32 | echo -e "${BD}Norminette libft:${X} ${G}OK${X}\n" 33 | read -n 1 -s -r -p "Press any key to continue..." 34 | return 0 35 | fi 36 | fi 37 | } 38 | 39 | check_compile_flags() { 40 | local makefile_flags=$(make -qpC .. | awk '/^CFLAGS/{for (i=3; i<=NF; i++) print $i}') 41 | 42 | for flag in "${flags[@]}"; do 43 | found=false 44 | for make_flag in $makefile_flags; do 45 | if [[ $make_flag == "$flag"* ]]; then 46 | found=true 47 | break 48 | fi 49 | done 50 | if ! $found; then 51 | echo -e "${BD}Compilation flag:${X} ${DM}$flag${X} ${R}MISSING${X}" 52 | return 1 53 | fi 54 | done 55 | echo -e "${BD}Compilation flag:${X} ${G}OK${X}" 56 | check_lib_norme 57 | } 58 | 59 | check_targets() { 60 | local makefile_targets=$(make -qpC .. | awk -F':' '/^[^.# ][^\t]*:/{print $1}') 61 | 62 | for target in "${targets[@]}"; do 63 | found=false 64 | for make_target in $makefile_targets; do 65 | if [[ $make_target == "$target"* ]]; then 66 | found=true 67 | break 68 | fi 69 | done 70 | if ! $found; then 71 | echo -e "${BD}Makefile targets:${X} ${DM}$target${X} ${R}MISSING${X}" 72 | return 1 73 | fi 74 | done 75 | echo -e "${BD}Makefile targets:${X} ${G}OK${X}" 76 | check_compile_flags 77 | } 78 | 79 | check_files() { 80 | if [ -n "$1" ]; then 81 | targets+=("$1") 82 | fi 83 | for file in "${files[@]}"; do 84 | if [ -e "$dir/$file" ]; then 85 | echo -e "${BD}$file:${X} ${G}OK${X}" 86 | else 87 | echo -e "${BD}$file:${X} ${R}MISSING${X}" 88 | return 1 89 | fi 90 | done 91 | check_targets 92 | } 93 | 94 | check_files $1 -------------------------------------------------------------------------------- /scripts/check_hostname.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | check_hostname() { 4 | local hostname=$(hostname) 5 | local prefixes=("paul" "made" "bess") 6 | 7 | for prefix in "${prefixes[@]}"; do 8 | [[ $hostname == $prefix* ]] && return 1 9 | done 10 | return 0 11 | } 12 | 13 | check_hostname -------------------------------------------------------------------------------- /scripts/check_norminette_version.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | check_norminette_version() { 4 | local current_version=$(norminette -v | awk '{print $2}') 5 | local base_version="3.3.51" 6 | 7 | if [[ $(echo -e "$base_version\n$current_version" | sort -V | head -n1) == $base_version ]]; then 8 | if [[ $current_version == $base_version ]]; then 9 | return 1 10 | else 11 | return 0 12 | fi 13 | else 14 | return 1 15 | fi 16 | } 17 | 18 | check_norminette_version -------------------------------------------------------------------------------- /scripts/check_sysfunc.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | declare -A executable_whitelists 4 | executable_whitelists["../ft_isalpha.o"]="" 5 | executable_whitelists["../ft_isdigit.o"]="" 6 | executable_whitelists["../ft_isalnum.o"]="" 7 | executable_whitelists["../t_isascii.o"]="" 8 | executable_whitelists["../ft_isprint.o"]="" 9 | executable_whitelists["../ft_strlen.o"]="" 10 | executable_whitelists["../ft_memset.o"]="" 11 | executable_whitelists["../ft_bzero.o"]="" 12 | executable_whitelists["../ft_memcpy.o"]="" 13 | executable_whitelists["../ft_memmove.o"]="" 14 | executable_whitelists["../ft_strlcpy.o"]="" 15 | executable_whitelists["../ft_strlcat.o"]="" 16 | executable_whitelists["../ft_tolower.o"]="" 17 | executable_whitelists["../ft_toupper.o"]="" 18 | executable_whitelists["../ft_strchr.o"]="" 19 | executable_whitelists["../ft_strrchr.o"]="" 20 | executable_whitelists["../ft_strncmp.o"]="" 21 | executable_whitelists["../ft_memchr.o"]="" 22 | executable_whitelists["../ft_memcmp.o"]="" 23 | executable_whitelists["../ft_strnstr.o"]="" 24 | executable_whitelists["../ft_atoi.o"]="" 25 | executable_whitelists["../ft_calloc.o"]="malloc" 26 | executable_whitelists["../ft_strdup.o"]="malloc" 27 | executable_whitelists["../ft_substr.o"]="malloc" 28 | executable_whitelists["../ft_strjoin.o"]="malloc" 29 | executable_whitelists["../ft_strtrim.o"]="malloc" 30 | executable_whitelists["../ft_split.o"]="malloc,free" 31 | executable_whitelists["../ft_itoa.o"]="malloc" 32 | executable_whitelists["../ft_strmapi.o"]="malloc" 33 | executable_whitelists["../ft_striteri.o"]="" 34 | executable_whitelists["../ft_putchar_fd.o"]="write" 35 | executable_whitelists["../ft_putstr_fd.o"]="write" 36 | executable_whitelists["../ft_putendl_fd.o"]="write" 37 | executable_whitelists["../ft_putnbr_fd.o"]="write" 38 | executable_whitelists["../ft_lstnew_bonus.o"]="malloc" 39 | executable_whitelists["../ft_lstadd_front_bonus.o"]="" 40 | executable_whitelists["../ft_lstsize_bonus.o"]="" 41 | executable_whitelists["../ft_lstlast_bonus.o"]="" 42 | executable_whitelists["../ft_lstadd_back_bonus.o"]="" 43 | executable_whitelists["../ft_lstdelone_bonus.o"]="free" 44 | executable_whitelists["../ft_lstclear_bonus.o"]="free" 45 | executable_whitelists["../ft_lstiter_bonus.o"]="" 46 | executable_whitelists["../ft_lstmap_bonus.o"]="malloc,free" 47 | 48 | check_sysfunc() { 49 | local file="$1" 50 | local whitelist_str="${executable_whitelists[$file]}" 51 | local whitelist=() 52 | local symbols=$(nm "$file" | grep ' U ' | awk '{print $2}') 53 | local forbidden_calls=() 54 | 55 | if [ -n "$whitelist_str" ]; then 56 | IFS=',' read -r -a whitelist <<< "$whitelist_str" 57 | fi 58 | for symbol in $symbols; do 59 | local found=0 60 | if [[ "$symbol" =~ ^(ft_|__) ]]; then 61 | continue 62 | fi 63 | for allowed_call in "${whitelist[@]}"; do 64 | if [ "$symbol" == "$allowed_call" ]; then 65 | found=1 66 | break 67 | fi 68 | done 69 | if [ $found -eq 0 ]; then 70 | forbidden_calls+=("$symbol") 71 | fi 72 | done 73 | if [ ${#forbidden_calls[@]} -eq 0 ]; then 74 | echo "Forbidden system function calls: OK" 75 | return 1 76 | else 77 | echo "Forbidden system function calls detected:" 78 | for forbidden_call in "${forbidden_calls[@]}"; do 79 | echo "- $forbidden_call" 80 | done 81 | return 0 82 | fi 83 | } 84 | 85 | check_sysfunc "$1" -------------------------------------------------------------------------------- /scripts/show_func.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | find ../ -maxdepth 1 -type f -name 'ft_*.c' -exec basename -s .c {} \; | sort -------------------------------------------------------------------------------- /scripts/title.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | B='\e[94m' 4 | G='\e[90m' 5 | C='\e[96m' 6 | IT='\e[3m' 7 | X='\e[0m' 8 | 9 | clear 10 | printf "\n" 11 | printf "${B}██${G}╗ ${B}██${G}╗${B}██████${G}╗ ${B}████████${G}╗${B}███████${G}╗${B}███████${G}╗${B}████████${G}╗\n" 12 | printf "${B}██${G}║ ${B}██${G}║${B}██${G}╔══${B}██${G}╗╚══${B}██${G}╔══╝${B}██${G}╔════╝${B}██${G}╔════╝╚══${B}██${G}╔══╝\n" 13 | printf "${B}██${G}║ ${B}██${G}║${B}██████${G}╔╝ ${B}██${G}║ ${B}█████${G}╗ ${B}███████${G}╗ ${B}██${G}║ \n" 14 | printf "${B}██${G}║ ${B}██${G}║${B}██${G}╔══${B}██${G}╗ ${B}██${G}║ ${B}██${G}╔══╝ ╚════${B}██${G}║ ${B}██${G}║ \n" 15 | printf "${B}███████${G}╗${B}██${G}║${B}██████${G}╔╝ ${B}██${G}║ ${B}███████${G}╗${B}███████${G}║ ${B}██${G}║ \n" 16 | printf "${G}╚══════╝╚═╝╚═════╝ ╚═╝ ╚══════╝╚══════╝ ╚═╝ ${X}${IT}by ${C}FonWasH${X}\n" -------------------------------------------------------------------------------- /srcs/ft_call_test.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_call_test.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: juperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2024/03/16 08:42:22 by juperez #+# #+# */ 9 | /* Updated: 2024/05/19 14:41:16 by juperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libtest.h" 14 | 15 | static bool ft_check_functions(char *name, const t_ftest *ftest) 16 | { 17 | for (size_t i = 0; ftest[i].name; i++) 18 | { 19 | if (!strcmp(name, ftest[i].name) && (*ftest[i].f)) 20 | { 21 | system(TITLE); 22 | printf("\n"); 23 | ft_print_name(name); 24 | if (ft_test_norminette(name) && ft_check_sysfunc(name)) 25 | { 26 | ft_reset_presult(); 27 | ft_time_function(RESET); 28 | ft_grade((*ftest[i].f)(name)); 29 | } 30 | return (true); 31 | } 32 | } 33 | return (false); 34 | } 35 | 36 | bool ft_call_test(char *name) 37 | { 38 | if (!ft_check_functions(name, g_fmandatory)) 39 | if (!ft_check_functions(name, g_fbonus)) 40 | return (false); 41 | return (true); 42 | } 43 | 44 | void ft_call_all_test(bool title, bool force, const t_ftest *ftest) 45 | { 46 | if (title) 47 | system(TITLE); 48 | for (size_t i = 0; ftest[i].name; i++) 49 | { 50 | if (!(*ftest[i].f)) 51 | continue ; 52 | printf("\n"); 53 | ft_print_name(ftest[i].name); 54 | if (force || (ft_test_norminette(ftest[i].name) && ft_check_sysfunc(ftest[i].name))) 55 | { 56 | ft_reset_presult(); 57 | ft_time_function(RESET); 58 | ft_grade((*ftest[i].f)(ftest[i].name)); 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /srcs/global/globals.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* globals.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: juperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2024/03/16 08:03:35 by juperez #+# #+# */ 9 | /* Updated: 2024/05/20 18:29:56 by juperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libtest.h" 14 | 15 | t_presult g_presult; 16 | t_result g_result; 17 | int g_node_freed; 18 | 19 | const t_ftest g_fmandatory[] = { 20 | {"ft_isalpha", ft_test_ascii}, 21 | {"ft_isdigit", ft_test_ascii}, 22 | {"ft_isalnum", ft_test_ascii}, 23 | {"ft_isascii", ft_test_ascii}, 24 | {"ft_isprint", ft_test_ascii}, 25 | {"ft_strlen", ft_test_strlen}, 26 | {"ft_memset", ft_test_memset}, 27 | {"ft_bzero", ft_test_bzero}, 28 | {"ft_memcpy", ft_test_memcpy}, 29 | {"ft_memmove", ft_test_memmove}, 30 | {"ft_strlcpy", ft_test_strlcpy}, 31 | {"ft_strlcat", ft_test_strlcat}, 32 | {"ft_tolower", ft_test_ascii}, 33 | {"ft_toupper", ft_test_ascii}, 34 | {"ft_strchr", ft_test_strchr}, 35 | {"ft_strrchr", ft_test_strrchr}, 36 | {"ft_strncmp", ft_test_strncmp}, 37 | {"ft_memchr", ft_test_memchr}, 38 | {"ft_memcmp", ft_test_memcmp}, 39 | {"ft_strnstr", ft_test_strnstr}, 40 | {"ft_atoi", ft_test_atoi}, 41 | {"ft_calloc", ft_test_calloc}, 42 | {"ft_strdup", ft_test_strdup}, 43 | {"ft_substr", ft_test_substr}, 44 | {"ft_strjoin", ft_test_strjoin}, 45 | {"ft_strtrim", ft_test_strtrim}, 46 | {"ft_split", ft_test_split}, 47 | {"ft_itoa", ft_test_itoa}, 48 | {"ft_strmapi", ft_test_strmapi}, 49 | {"ft_striteri", ft_test_striteri}, 50 | {"ft_putchar_fd", ft_test_putchar_fd}, 51 | {"ft_putstr_fd", ft_test_putstr_fd}, 52 | {"ft_putendl_fd", ft_test_putendl_fd}, 53 | {"ft_putnbr_fd", ft_test_putnbr_fd}, 54 | {NULL, NULL} 55 | }; 56 | 57 | const t_ftest g_fbonus[] = { 58 | {"ft_lstnew_bonus", ft_test_lstnew}, 59 | {"ft_lstadd_front_bonus", ft_test_lstadd_front}, 60 | {"ft_lstsize_bonus", ft_test_lstsize}, 61 | {"ft_lstlast_bonus", ft_test_lstlast}, 62 | {"ft_lstadd_back_bonus", ft_test_lstadd_back}, 63 | {"ft_lstdelone_bonus", ft_test_lstdelone}, 64 | {"ft_lstclear_bonus", ft_test_lstclear}, 65 | {"ft_lstiter_bonus", ft_test_lstiter}, 66 | {"ft_lstmap_bonus", ft_test_lstmap}, 67 | {NULL, NULL} 68 | }; 69 | 70 | const char *g_str1_tests[] = { 71 | "\t\n\v\f\r ", 72 | "Hello World!", 73 | "abcdefghijklmnopqrstuvwxyz", 74 | "42", 75 | "#", 76 | "", 77 | NULL 78 | }; 79 | 80 | const char *g_str2_tests[] = { 81 | "Hello World!", 82 | "Hello42", 83 | "abcdefghijklmnopqrstuvwxyz", 84 | "abcdefghijklmnopqrstuvwxyzABC", 85 | "abc", 86 | "abcABC", 87 | "42", 88 | "#", 89 | "", 90 | NULL 91 | }; 92 | 93 | const char *g_nbr_tests[] = { 94 | "42", 95 | "-42", 96 | "0", 97 | "-2147483648", 98 | "2147483647", 99 | "-1", 100 | "1", 101 | "100", 102 | NULL 103 | }; 104 | 105 | const char *g_sortn_tests[] = { 106 | "1", 107 | "2", 108 | "3", 109 | "4", 110 | "5", 111 | NULL 112 | }; 113 | 114 | const char *g_revn_tests[] = { 115 | "5", 116 | "4", 117 | "3", 118 | "2", 119 | "1", 120 | NULL 121 | }; 122 | 123 | const char *g_lowa_tests[] = { 124 | "a", 125 | "b", 126 | "c", 127 | "d", 128 | "e", 129 | NULL 130 | }; 131 | 132 | const char *g_uppa_tests[] = { 133 | "A", 134 | "B", 135 | "C", 136 | "D", 137 | "E", 138 | NULL 139 | }; -------------------------------------------------------------------------------- /srcs/main.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: juperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2024/03/07 04:47:10 by juperez #+# #+# */ 9 | /* Updated: 2024/05/07 11:20:22 by juperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libtest.h" 14 | 15 | int main(int ac, char *av[]) 16 | { 17 | if (ac > 1) 18 | { 19 | if (!strcmp(av[1], "--all") || !strcmp(av[1], "-a")) 20 | { 21 | ft_call_all_test(true, false, g_fmandatory); 22 | ft_call_all_test(false, false, g_fbonus); 23 | } 24 | else if (!strcmp(av[1], "--force") || !strcmp(av[1], "-f")) 25 | { 26 | ft_call_all_test(true, true, g_fmandatory); 27 | ft_call_all_test(false, true, g_fbonus); 28 | } 29 | else if (!strcmp(av[1], "--mandatory") || !strcmp(av[1], "-m")) 30 | ft_call_all_test(true, false, g_fmandatory); 31 | else if (!strcmp(av[1], "--bonus") || !strcmp(av[1], "-b")) 32 | ft_call_all_test(true, false, g_fbonus); 33 | else if (!strcmp(av[1], "--show") || !strcmp(av[1], "-s")) 34 | system(SHOW_FUNC); 35 | else if (!strcmp(av[1], "--help") || !strcmp(av[1], "-h")) 36 | ft_print_file(SHOW_HELP); 37 | else if (!strcmp(av[1], "--version") || !strcmp(av[1], "-v")) 38 | ft_print_file(SHOW_VERSION); 39 | else if (!ft_call_test(av[1])) 40 | printf("%s: invalid argument -- '%s'%s", 41 | basename(av[0]), av[1], ERROR_HELP); 42 | } 43 | else 44 | printf("%s: requires an argument%s", basename(av[0]), ERROR_HELP); 45 | return (EXIT_SUCCESS); 46 | } 47 | -------------------------------------------------------------------------------- /srcs/tests/ft_test_ascii.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_test_ascii.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: juperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2024/03/15 08:42:03 by juperez #+# #+# */ 9 | /* Updated: 2024/03/30 10:26:33 by juperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libtest.h" 14 | 15 | static void ft_get_functions(char *name, int (**user)(int), int (**libc)(int)) 16 | { 17 | const t_fascii fascii[] = { 18 | {"ft_isalnum", ft_isalnum, isalnum}, 19 | {"ft_isalpha", ft_isalpha, isalpha}, 20 | {"ft_isascii", ft_isascii, isascii}, 21 | {"ft_isdigit", ft_isdigit, isdigit}, 22 | {"ft_isprint", ft_isprint, isprint}, 23 | {"ft_tolower", ft_tolower, tolower}, 24 | {"ft_toupper", ft_toupper, toupper}, 25 | {NULL, NULL, NULL} 26 | }; 27 | 28 | for (size_t i = 0; fascii[i].name; i++) 29 | { 30 | if (!strcmp(name, fascii[i].name)) 31 | { 32 | *user = fascii[i].user; 33 | *libc = fascii[i].libc; 34 | } 35 | } 36 | } 37 | 38 | static bool ft_run_test(int (*f_user)(int), int (*f_libc)(int), int c) 39 | { 40 | int user, libc; 41 | 42 | ft_time_function(USER_START); 43 | user = (*f_user)(c); 44 | ft_time_function(USER_END_LIBC_START); 45 | libc = (*f_libc)(c); 46 | ft_time_function(LIBC_END); 47 | if (!(libc == user)) 48 | { 49 | ft_result_input_int(c); 50 | ft_result_output_int(user, libc); 51 | ft_print_result(true); 52 | return (false); 53 | } 54 | return (true); 55 | } 56 | 57 | static bool ft_test_irange(int (*f_user)(int), int (*f_libc)(int)) 58 | { 59 | int i = CHAR_MIN - 1, grade = CHAR_MIN - 1; 60 | 61 | while (i <= UCHAR_MAX + 1) 62 | { 63 | grade += ft_run_test(f_user, f_libc, i); 64 | i++; 65 | } 66 | return (grade == i); 67 | } 68 | 69 | bool ft_test_ascii(char *name) 70 | { 71 | int (*f_user)(int), (*f_libc)(int); 72 | 73 | ft_get_functions(name, &f_user, &f_libc); 74 | return (ft_test_irange(f_user, f_libc)); 75 | } 76 | -------------------------------------------------------------------------------- /srcs/tests/ft_test_atoi.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_test_atoi.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: juperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2024/03/15 09:48:50 by juperez #+# #+# */ 9 | /* Updated: 2024/05/21 16:13:20 by juperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libtest.h" 14 | 15 | const char *g_atoi_str[] = { 16 | "\t\n\v\f\r +00000042", 17 | " -42a", 18 | " a42", 19 | " -+--+42", 20 | "-2147483648", 21 | "2147483647", 22 | "0", 23 | "-00", 24 | "", 25 | "999999999999999", 26 | "-999999999999999", 27 | "9999999999999999999", 28 | "-9999999999999999999", 29 | "999999999999999999999", 30 | "-999999999999999999999", 31 | "0000000000000000000042", 32 | "9223372036854775805", 33 | "9223372036854775806", 34 | "9223372036854775807", 35 | "9223372036854775808", 36 | "9223372036854775809", 37 | "-9223372036854775805", 38 | "-9223372036854775806", 39 | "-9223372036854775807", 40 | "-9223372036854775808", 41 | "-9223372036854775809", 42 | NULL 43 | }; 44 | 45 | static bool ft_run_test(const char *nptr) 46 | { 47 | int user, libc; 48 | 49 | ft_time_function(USER_START); 50 | user = ft_atoi(nptr); 51 | ft_time_function(USER_END_LIBC_START); 52 | libc = atoi(nptr); 53 | ft_time_function(LIBC_END); 54 | if (!(user == libc)) 55 | { 56 | ft_result_input_str((char *)nptr, NULL); 57 | ft_result_output_int(user, libc); 58 | ft_print_result(true); 59 | return (false); 60 | } 61 | return (true); 62 | } 63 | 64 | bool ft_test_atoi(char *name) 65 | { 66 | size_t i = 0, grade = 0; 67 | 68 | (void)name; 69 | while (g_atoi_str[i]) 70 | { 71 | grade += ft_run_test(g_atoi_str[i]); 72 | i++; 73 | } 74 | return (grade == i); 75 | } 76 | -------------------------------------------------------------------------------- /srcs/tests/ft_test_bzero.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_test_bzero.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: juperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2024/03/20 21:07:19 by juperez #+# #+# */ 9 | /* Updated: 2024/03/30 10:26:37 by juperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libtest.h" 14 | 15 | static bool ft_run_test(size_t n) 16 | { 17 | char user[] = "................"; 18 | char libc[] = "................"; 19 | 20 | ft_time_function(USER_START); 21 | ft_bzero((void *)user, n); 22 | ft_time_function(USER_END_LIBC_START); 23 | bzero((void *)libc, n); 24 | ft_time_function(LIBC_END); 25 | if (strcmp(user, libc)) 26 | { 27 | ft_result_input_sizet(n); 28 | ft_result_output_str(user, libc); 29 | ft_print_result(true); 30 | return (false); 31 | } 32 | return (true); 33 | } 34 | 35 | bool ft_test_bzero(char *name) 36 | { 37 | size_t i = 0, grade = 0; 38 | 39 | (void)name; 40 | while (i < 16) 41 | { 42 | grade += ft_run_test(i); 43 | i++; 44 | } 45 | return (grade == i); 46 | } 47 | -------------------------------------------------------------------------------- /srcs/tests/ft_test_calloc.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_test_calloc.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: juperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2024/03/27 09:30:43 by juperez #+# #+# */ 9 | /* Updated: 2024/03/30 10:26:38 by juperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libtest.h" 14 | 15 | static bool ft_run_test(size_t nmemb, size_t size) 16 | { 17 | size_t i = (nmemb && size && (SIZE_MAX / nmemb < size)) ? nmemb * size : 1; 18 | char str_nmemb[21], str_size[21]; 19 | char *user, *libc; 20 | 21 | ft_time_function(USER_START); 22 | user = (char *)ft_calloc(nmemb, size); 23 | ft_time_function(USER_END_LIBC_START); 24 | libc = (char *)calloc(nmemb, size); 25 | ft_time_function(LIBC_END); 26 | memset((void *)user, '.', i); 27 | memset((void *)libc, '.', i); 28 | user[i - 1] = '\0'; 29 | libc[i - 1] = '\0'; 30 | if (strcmp(user, libc)) 31 | { 32 | sprintf(str_nmemb, "%zu", nmemb); 33 | sprintf(str_size, "%zu", size); 34 | ft_result_input_str(str_nmemb, str_size); 35 | ft_result_output_str(user, libc); 36 | ft_print_result(true); 37 | free(user); 38 | free(libc); 39 | return (false); 40 | } 41 | free(user); 42 | free(libc); 43 | return (true); 44 | } 45 | 46 | bool ft_test_calloc(char *name) 47 | { 48 | size_t nmemb[] = {0, 10, 0, 10, 100}; //SIZE_MAX 18446744073709551615 49 | size_t size[] = {0, 0, 10, 10, 100}; 50 | size_t i = 0, grade = 0, count = sizeof(size) / sizeof(size[0]); 51 | 52 | (void)name; 53 | while (i < count) 54 | { 55 | grade += ft_run_test(nmemb[i], size[i]); 56 | i++; 57 | } 58 | return (grade == i); 59 | } 60 | -------------------------------------------------------------------------------- /srcs/tests/ft_test_itoa.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_test_itoa.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: juperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2024/03/15 09:48:58 by juperez #+# #+# */ 9 | /* Updated: 2024/03/30 19:51:01 by juperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libtest.h" 14 | 15 | static bool ft_run_test(char *n_str) 16 | { 17 | int n = atoi(n_str); 18 | char *user; 19 | 20 | ft_time_function(USER_START); 21 | user = ft_itoa(n); 22 | ft_time_function(USER_END); 23 | if (strcmp(user, n_str)) 24 | { 25 | ft_result_input_int(n); 26 | ft_result_output_str(user, n_str); 27 | ft_print_result(false); 28 | free(user); 29 | return (false); 30 | } 31 | free(user); 32 | return (true); 33 | } 34 | 35 | bool ft_test_itoa(char *name) 36 | { 37 | size_t i = 0, grade = 0; 38 | 39 | (void)name; 40 | while (g_nbr_tests[i]) 41 | { 42 | grade += ft_run_test((char *)g_nbr_tests[i]); 43 | i++; 44 | } 45 | return (grade == i); 46 | } 47 | -------------------------------------------------------------------------------- /srcs/tests/ft_test_lstadd_back.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_test_lstadd_back.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: juperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2024/03/27 09:34:02 by juperez #+# #+# */ 9 | /* Updated: 2024/05/20 15:39:47 by juperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libtest.h" 14 | 15 | static bool ft_run_test(void) 16 | { 17 | t_list *user = NULL; 18 | t_list *tmp = NULL; 19 | size_t user_size = 0, size = 0; 20 | 21 | ft_time_function(USER_START); 22 | while (g_revn_tests[size]) 23 | { 24 | ft_lstadd_back(&user, ft_lstnew((void *)g_sortn_tests[size])); 25 | size++; 26 | } 27 | ft_time_function(USER_END); 28 | tmp = user; 29 | user_size = ft_lst_size(user); 30 | if (user_size != size) 31 | { 32 | ft_result_input_sizet(size); 33 | ft_result_output_sizet(user_size, size); 34 | ft_print_result(false); 35 | printf(LST_SIZE); 36 | ft_free_lst(user); 37 | return (false); 38 | } 39 | for (size_t i = 0; g_sortn_tests[i]; i++) 40 | { 41 | if (strcmp((char *)tmp->content, (char *)g_sortn_tests[i])) 42 | { 43 | ft_result_input_str((char *)g_sortn_tests[i], NULL); 44 | ft_result_output_str((char *)tmp->content, (char *)g_sortn_tests[i]); 45 | ft_print_result(false); 46 | ft_free_lst(user); 47 | return (false); 48 | } 49 | tmp = tmp->next; 50 | } 51 | ft_free_lst(user); 52 | return (true); 53 | } 54 | 55 | bool ft_test_lstadd_back(char *name) 56 | { 57 | (void)name; 58 | return (ft_run_test()); 59 | } 60 | -------------------------------------------------------------------------------- /srcs/tests/ft_test_lstadd_front.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_test_lstadd_front.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: juperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2024/03/27 09:33:25 by juperez #+# #+# */ 9 | /* Updated: 2024/05/20 15:39:41 by juperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libtest.h" 14 | 15 | static bool ft_run_test(void) 16 | { 17 | t_list *user = NULL; 18 | t_list *tmp = NULL; 19 | size_t user_size = 0, size = 0; 20 | 21 | ft_time_function(USER_START); 22 | while (g_revn_tests[size]) 23 | { 24 | ft_lstadd_front(&user, ft_lstnew((void *)g_revn_tests[size])); 25 | size++; 26 | } 27 | ft_time_function(USER_END); 28 | tmp = user; 29 | user_size = ft_lst_size(user); 30 | if (user_size != size) 31 | { 32 | ft_result_input_sizet(size); 33 | ft_result_output_sizet(user_size, size); 34 | ft_print_result(false); 35 | printf(LST_SIZE); 36 | ft_free_lst(user); 37 | return (false); 38 | } 39 | for (size_t i = 0; g_sortn_tests[i]; i++) 40 | { 41 | if (strcmp((char *)tmp->content, (char *)g_sortn_tests[i])) 42 | { 43 | ft_result_input_str((char *)g_sortn_tests[i], NULL); 44 | ft_result_output_str((char *)tmp->content, (char *)g_sortn_tests[i]); 45 | ft_print_result(false); 46 | ft_free_lst(user); 47 | return (false); 48 | } 49 | tmp = tmp->next; 50 | } 51 | ft_free_lst(user); 52 | return (true); 53 | } 54 | 55 | bool ft_test_lstadd_front(char *name) 56 | { 57 | (void)name; 58 | return (ft_run_test()); 59 | } 60 | -------------------------------------------------------------------------------- /srcs/tests/ft_test_lstclear.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_test_lstclear.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: juperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2024/03/27 09:34:28 by juperez #+# #+# */ 9 | /* Updated: 2024/05/20 15:37:01 by juperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libtest.h" 14 | 15 | static bool ft_run_test(void) 16 | { 17 | t_list *lst = NULL; 18 | 19 | for (size_t i = 0; g_revn_tests[i]; i++) 20 | ft_lstadd_back(&lst, ft_lstnew((void *)strdup(g_revn_tests[i]))); 21 | ft_time_function(USER_START); 22 | ft_lstclear(&lst, ft_test_free); 23 | ft_time_function(USER_END); 24 | if (g_node_freed != 1) 25 | { 26 | ft_print_result(false); 27 | printf(LST_FREE); 28 | return (false); 29 | } 30 | return (true); 31 | } 32 | 33 | bool ft_test_lstclear(char *name) 34 | { 35 | (void)name; 36 | g_node_freed = 0; 37 | return (ft_run_test()); 38 | } 39 | -------------------------------------------------------------------------------- /srcs/tests/ft_test_lstdelone.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_test_lstdelone.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: juperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2024/03/27 09:34:14 by juperez #+# #+# */ 9 | /* Updated: 2024/05/20 15:37:26 by juperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libtest.h" 14 | 15 | static bool ft_run_test(void) 16 | { 17 | t_list *lst = NULL; 18 | 19 | lst = ft_lstnew(ft_strdup("test")); 20 | ft_time_function(USER_START); 21 | ft_lstdelone(lst, ft_test_free); 22 | ft_time_function(USER_END); 23 | if (g_node_freed != 1) 24 | { 25 | ft_print_result(false); 26 | printf(LST_FREE); 27 | return (false); 28 | } 29 | return (true); 30 | } 31 | 32 | bool ft_test_lstdelone(char *name) 33 | { 34 | (void)name; 35 | g_node_freed = 0; 36 | return (ft_run_test()); 37 | } 38 | -------------------------------------------------------------------------------- /srcs/tests/ft_test_lstiter.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_test_lstiter.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: juperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2024/03/27 09:34:38 by juperez #+# #+# */ 9 | /* Updated: 2024/05/20 15:49:46 by juperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libtest.h" 14 | 15 | static bool ft_run_test(void) 16 | { 17 | t_list *lst = NULL; 18 | t_list *tmp = NULL; 19 | 20 | for (size_t i = 0; g_lowa_tests[i]; i++) 21 | ft_lstadd_back(&lst, ft_lstnew(strdup((char *)g_lowa_tests[i]))); 22 | ft_time_function(USER_START); 23 | ft_lstiter(lst, ft_strtoupper); 24 | ft_time_function(USER_END); 25 | tmp = lst; 26 | for (size_t i = 0; g_uppa_tests[i]; i++) 27 | { 28 | if (strcmp((char *)tmp->content, (char *)g_uppa_tests[i])) 29 | { 30 | ft_result_input_str((char *)g_uppa_tests[i], NULL); 31 | ft_result_output_str((char *)tmp->content, (char *)g_uppa_tests[i]); 32 | ft_print_result(false); 33 | ft_lstclear(&lst, free); 34 | return (false); 35 | } 36 | tmp = tmp->next; 37 | } 38 | ft_lstclear(&lst, free); 39 | return (true); 40 | } 41 | 42 | bool ft_test_lstiter(char *name) 43 | { 44 | (void)name; 45 | return (ft_run_test()); 46 | } 47 | -------------------------------------------------------------------------------- /srcs/tests/ft_test_lstlast.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_test_lstlast.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: juperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2024/03/27 09:33:51 by juperez #+# #+# */ 9 | /* Updated: 2024/05/20 15:38:28 by juperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libtest.h" 14 | 15 | static bool ft_run_test(void) 16 | { 17 | t_list *lst = NULL, *last = NULL; 18 | size_t i = 0; 19 | 20 | while (g_revn_tests[i]) 21 | { 22 | ft_lstadd_front(&lst, ft_lstnew((void *)g_revn_tests[i])); 23 | i++; 24 | } 25 | ft_time_function(USER_START); 26 | last = ft_lstlast(lst); 27 | ft_time_function(USER_END); 28 | if (strcmp((char *)last->content, (char *)g_sortn_tests[i - 1])) 29 | { 30 | ft_result_input_str((char *)g_sortn_tests[i - 1], NULL); 31 | ft_result_output_str((char *)last->content, (char *)g_sortn_tests[i - 1]); 32 | ft_print_result(false); 33 | ft_free_lst(lst); 34 | return (false); 35 | } 36 | ft_free_lst(lst); 37 | return (true); 38 | } 39 | 40 | bool ft_test_lstlast(char *name) 41 | { 42 | (void)name; 43 | return (ft_run_test()); 44 | } 45 | -------------------------------------------------------------------------------- /srcs/tests/ft_test_lstmap.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_test_lstmap.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: juperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2024/03/27 09:34:50 by juperez #+# #+# */ 9 | /* Updated: 2024/05/20 15:58:06 by juperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libtest.h" 14 | 15 | static bool ft_run_test(void) 16 | { 17 | t_list *lst = NULL; 18 | t_list *new = NULL; 19 | t_list *tmp = NULL; 20 | 21 | for (size_t i = 0; g_lowa_tests[i]; i++) 22 | ft_lstadd_back(&lst, ft_lstnew(strdup((char *)g_lowa_tests[i]))); 23 | ft_time_function(USER_START); 24 | new = ft_lstmap(lst, ft_duptoupper, free); 25 | ft_time_function(USER_END); 26 | tmp = new; 27 | for (size_t i = 0; g_uppa_tests[i]; i++) 28 | { 29 | if (strcmp((char *)tmp->content, (char *)g_uppa_tests[i])) 30 | { 31 | ft_result_input_str((char *)g_uppa_tests[i], NULL); 32 | ft_result_output_str((char *)tmp->content, (char *)g_uppa_tests[i]); 33 | ft_print_result(false); 34 | ft_lstclear(&lst, free); 35 | ft_lstclear(&new, free); 36 | return (false); 37 | } 38 | tmp = tmp->next; 39 | } 40 | ft_lstclear(&lst, free); 41 | ft_lstclear(&new, free); 42 | return (true); 43 | } 44 | 45 | bool ft_test_lstmap(char *name) 46 | { 47 | (void)name; 48 | return (ft_run_test()); 49 | } 50 | -------------------------------------------------------------------------------- /srcs/tests/ft_test_lstnew.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_test_lstnew.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: juperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2024/03/27 09:33:12 by juperez #+# #+# */ 9 | /* Updated: 2024/05/19 16:08:01 by juperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libtest.h" 14 | 15 | static bool ft_run_test(void *content) 16 | { 17 | t_list *user = NULL; 18 | 19 | ft_time_function(USER_START); 20 | user = ft_lstnew(content); 21 | ft_time_function(USER_END); 22 | if (strcmp((char *)user->content, (char *)content)) 23 | { 24 | ft_result_input_str((char *)content, NULL); 25 | ft_result_output_str((char *)user->content, NULL); 26 | ft_print_result(false); 27 | free(user); 28 | return (false); 29 | } 30 | free(user); 31 | return (true); 32 | } 33 | 34 | bool ft_test_lstnew(char *name) 35 | { 36 | size_t i = 0, grade = 0; 37 | 38 | (void)name; 39 | while (g_str2_tests[i]) 40 | { 41 | grade += ft_run_test((void *)g_str2_tests[i]); 42 | i++; 43 | } 44 | return (grade == i); 45 | } 46 | -------------------------------------------------------------------------------- /srcs/tests/ft_test_lstsize.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_test_lstsize.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: juperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2024/03/27 09:33:39 by juperez #+# #+# */ 9 | /* Updated: 2024/05/20 15:39:27 by juperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libtest.h" 14 | 15 | static bool ft_run_test(void) 16 | { 17 | t_list *lst = NULL; 18 | size_t user_size = 0, size = 0; 19 | 20 | for (size_t i = 0; g_sortn_tests[i]; i++) 21 | ft_lstadd_front(&lst, ft_lstnew((void *)g_sortn_tests[i])); 22 | ft_time_function(USER_START); 23 | user_size = ft_lstsize(lst); 24 | ft_time_function(USER_END); 25 | size = ft_lst_size(lst); 26 | if (user_size != size) 27 | { 28 | ft_result_input_sizet(size); 29 | ft_result_output_sizet(user_size, size); 30 | ft_print_result(false); 31 | printf(LST_SIZE); 32 | ft_free_lst(lst); 33 | return (false); 34 | } 35 | ft_free_lst(lst); 36 | return (true); 37 | } 38 | 39 | bool ft_test_lstsize(char *name) 40 | { 41 | (void)name; 42 | return (ft_run_test()); 43 | } 44 | -------------------------------------------------------------------------------- /srcs/tests/ft_test_memchr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_test_memchr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: juperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2024/03/27 09:30:00 by juperez #+# #+# */ 9 | /* Updated: 2024/03/30 10:26:39 by juperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libtest.h" 14 | 15 | static bool ft_run_test(const void *s, int c, size_t n) 16 | { 17 | void *user, *libc; 18 | 19 | ft_time_function(USER_START); 20 | user = ft_memchr(s, c, n); 21 | ft_time_function(USER_END_LIBC_START); 22 | libc = memchr(s, c, n); 23 | ft_time_function(LIBC_END); 24 | if (!(user == libc)) 25 | { 26 | ft_result_input_str((char *)s, NULL); 27 | ft_result_input_int(c); 28 | ft_result_input_sizet(n); 29 | ft_result_output_str((char *)user, (char *)libc); 30 | ft_print_result(true); 31 | return (false); 32 | } 33 | return (true); 34 | } 35 | 36 | static bool ft_test_size(const void *s, int c) 37 | { 38 | size_t i = 0, grade = 0, size = strlen(s); 39 | 40 | while (i < size) 41 | { 42 | grade += ft_run_test(s, c, i); 43 | i++; 44 | } 45 | return (grade == i); 46 | } 47 | 48 | bool ft_test_memchr(char *name) 49 | { 50 | int i = CHAR_MIN - 1, grade = CHAR_MIN - 1; 51 | 52 | (void)name; 53 | while (i <= UCHAR_MAX + 1) 54 | { 55 | grade += ft_test_size((const void *)g_str1_tests[1], i); 56 | i++; 57 | } 58 | return (grade == i); 59 | } 60 | -------------------------------------------------------------------------------- /srcs/tests/ft_test_memcmp.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_test_memcmp.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: juperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2024/03/27 09:30:15 by juperez #+# #+# */ 9 | /* Updated: 2024/03/30 10:26:43 by juperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libtest.h" 14 | 15 | static bool ft_run_test(const void *s1, const void *s2, size_t n) 16 | { 17 | int user, libc; 18 | 19 | ft_time_function(USER_START); 20 | user = ft_memcmp(s1, s2, n); 21 | ft_time_function(USER_END_LIBC_START); 22 | libc = memcmp(s1, s2, n); 23 | ft_time_function(LIBC_END); 24 | if (!(user == libc)) 25 | { 26 | ft_result_input_sizet(n); 27 | ft_result_input_str((char *)s1, (char *)s2); 28 | ft_result_output_int(user, libc); 29 | ft_print_result(true); 30 | return (false); 31 | } 32 | return (true); 33 | } 34 | 35 | static bool ft_test_size(const void *s1, const void *s2) 36 | { 37 | size_t s1_len = strlen((char *)s1), s2_len = strlen((char *)s2); 38 | size_t size = s1_len <= s2_len ? s1_len : s2_len; 39 | size_t i = 0, grade = 0; 40 | 41 | while (i < size) 42 | { 43 | grade += ft_run_test(s1, s2, i); 44 | i++; 45 | } 46 | return (grade == i); 47 | } 48 | 49 | static bool ft_test_tofind(const void *s1) 50 | { 51 | size_t i = 0, grade = 0; 52 | 53 | while (g_str2_tests[i]) 54 | { 55 | grade += ft_test_size(s1, (const void *)g_str2_tests[i]); 56 | i++; 57 | } 58 | return (grade == i); 59 | } 60 | 61 | bool ft_test_memcmp(char *name) 62 | { 63 | size_t i = 0, grade = 0; 64 | 65 | (void)name; 66 | while (g_str1_tests[i]) 67 | { 68 | grade += ft_test_tofind((const void *)g_str1_tests[i]); 69 | i++; 70 | } 71 | return (grade == i); 72 | } 73 | -------------------------------------------------------------------------------- /srcs/tests/ft_test_memcpy.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_test_memcpy.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: juperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2024/03/20 21:39:19 by juperez #+# #+# */ 9 | /* Updated: 2024/03/30 10:26:44 by juperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libtest.h" 14 | 15 | static bool ft_run_test(const void *src, size_t n) 16 | { 17 | char user[] = "................"; 18 | char libc[] = "................"; 19 | 20 | n = n > 16 ? 16 : n; 21 | ft_time_function(USER_START); 22 | ft_memcpy((void *)user, src, n); 23 | ft_time_function(USER_END_LIBC_START); 24 | memcpy((void *)libc, src, n); 25 | ft_time_function(LIBC_END); 26 | if (strcmp(user, libc)) 27 | { 28 | ft_result_input_sizet(n); 29 | ft_result_input_str((char *)src, NULL); 30 | ft_result_output_str(user, libc); 31 | ft_print_result(true); 32 | } 33 | return (true); 34 | } 35 | 36 | bool ft_test_memcpy(char *name) 37 | { 38 | size_t i = 0, grade = 0; 39 | 40 | (void)name; 41 | while (g_str1_tests[i]) 42 | { 43 | grade += ft_run_test((const void *)g_str1_tests[i], strlen(g_str1_tests[i])); 44 | i++; 45 | } 46 | return (grade == i); 47 | } 48 | -------------------------------------------------------------------------------- /srcs/tests/ft_test_memmove.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_test_memmove.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: juperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2024/03/21 02:18:39 by juperez #+# #+# */ 9 | /* Updated: 2024/05/22 01:24:19 by juperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libtest.h" 14 | 15 | static bool ft_run_test(void *user_dest, const void *user_src, void *libc_dest, const void *libc_src, size_t n) 16 | { 17 | ft_time_function(USER_START); 18 | ft_memmove(user_dest, user_src, n); 19 | ft_time_function(USER_END_LIBC_START); 20 | memmove(libc_dest, libc_src, n); 21 | ft_time_function(LIBC_END); 22 | if (strcmp(user_dest, libc_dest)) 23 | return (false); 24 | return (true); 25 | } 26 | 27 | static bool ft_test_ptr_pos(void *user, void *libc, size_t n, size_t *pos) 28 | { 29 | *pos = 1; 30 | if (!ft_run_test(user, (const void *)user, libc, (const void *)libc, n)) 31 | return (false); 32 | *pos = 2; 33 | if (!ft_run_test(user, (const void *)user + 5, libc, (const void *)libc + 5, n)) 34 | return (false); 35 | *pos = 3; 36 | if (!ft_run_test(user + 6, (const void *)user, libc + 6, (const void *)libc, n)) 37 | return (false); 38 | return (true); 39 | } 40 | 41 | bool ft_test_memmove(char *name) 42 | { 43 | char user[] = "abcdefghijklmnopqrst"; 44 | char libc[] = "abcdefghijklmnopqrst"; 45 | size_t i = 0, grade = 0, pos; 46 | bool success; 47 | 48 | (void)name; 49 | while (i < 10) 50 | { 51 | success = ft_test_ptr_pos((void *)user, (void *)libc, i, &pos); 52 | if (!success) 53 | { 54 | ft_result_input_sizet(i); 55 | ft_result_output_str((char *)user, (char *)libc); 56 | ft_print_result(true); 57 | printf("%s%s", MEM, pos == 1 ? EQU : pos == 2 ? HIG : LOW); 58 | } 59 | grade += success; 60 | i++; 61 | } 62 | return (grade == i); 63 | } 64 | -------------------------------------------------------------------------------- /srcs/tests/ft_test_memset.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_test_memset.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: juperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2024/03/19 08:06:06 by juperez #+# #+# */ 9 | /* Updated: 2024/03/30 10:26:47 by juperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libtest.h" 14 | 15 | static bool ft_run_test(int c, size_t n) 16 | { 17 | char user[] = "................"; 18 | char libc[] = "................"; 19 | 20 | ft_time_function(USER_START); 21 | ft_memset(user, c, n); 22 | ft_time_function(USER_END_LIBC_START); 23 | memset(libc, c, n); 24 | ft_time_function(LIBC_END); 25 | if (strcmp(user, libc)) 26 | { 27 | ft_result_input_sizet(n); 28 | ft_result_input_int(c); 29 | ft_result_output_str(user, libc); 30 | ft_print_result(true); 31 | return (false); 32 | } 33 | return (true); 34 | } 35 | 36 | static bool ft_test_size(int c) 37 | { 38 | size_t i = 0, grade = 0; 39 | 40 | while (i < 16) 41 | { 42 | grade += ft_run_test(c, i); 43 | i++; 44 | } 45 | return (grade == i); 46 | } 47 | 48 | bool ft_test_memset(char *name) 49 | { 50 | int i = CHAR_MIN - 1, grade = CHAR_MIN - 1; 51 | 52 | (void)name; 53 | while (i <= UCHAR_MAX + 1) 54 | { 55 | grade += ft_test_size(i); 56 | i++; 57 | } 58 | return (grade == i); 59 | } 60 | -------------------------------------------------------------------------------- /srcs/tests/ft_test_putchar_fd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_test_putchar_fd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: juperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2024/03/27 09:32:17 by juperez #+# #+# */ 9 | /* Updated: 2024/05/21 19:19:39 by juperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libtest.h" 14 | 15 | static bool ft_run_test(char c) 16 | { 17 | int pipefd[2]; 18 | char user[BUFFER_SIZE]; 19 | 20 | memset(user, 0, sizeof(user)); 21 | pipe(pipefd); 22 | ft_time_function(USER_START); 23 | ft_putchar_fd(c, pipefd[1]); 24 | ft_time_function(USER_END); 25 | read(pipefd[0], user, BUFFER_SIZE); 26 | if (!(user[0] == c)) 27 | { 28 | ft_result_input_chr(c); 29 | ft_result_output_chr(user[0], c); 30 | ft_print_result(false); 31 | close(pipefd[0]); 32 | close(pipefd[1]); 33 | return (false); 34 | } 35 | close(pipefd[0]); 36 | close(pipefd[1]); 37 | return (true); 38 | } 39 | 40 | bool ft_test_putchar_fd(char *name) 41 | { 42 | size_t i = 0, grade = 0; 43 | 44 | (void)name; 45 | while (g_str1_tests[1][i]) 46 | { 47 | grade += ft_run_test(g_str1_tests[1][i]); 48 | i++; 49 | } 50 | return (grade == i); 51 | } 52 | -------------------------------------------------------------------------------- /srcs/tests/ft_test_putendl_fd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_test_putendl_fd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: juperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2024/03/27 09:32:43 by juperez #+# #+# */ 9 | /* Updated: 2024/05/21 19:19:46 by juperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libtest.h" 14 | 15 | const char *g_eputendl[] = { 16 | "\t\n\v\f\r \n", 17 | "Hello World!\n", 18 | "abcdefghijklmnopqrstuvwxyz\n", 19 | "42\n", 20 | "#\n", 21 | "\n", 22 | NULL 23 | }; 24 | 25 | static bool ft_run_test(char *s, char *e) 26 | { 27 | int pipefd[2]; 28 | char user[BUFFER_SIZE]; 29 | 30 | memset(user, 0, sizeof(user)); 31 | pipe(pipefd); 32 | ft_time_function(USER_START); 33 | ft_putendl_fd(s, pipefd[1]); 34 | ft_time_function(USER_END); 35 | read(pipefd[0], user, strlen(s) + 1); 36 | if (strcmp(user, e)) 37 | { 38 | ft_result_input_str(s, NULL); 39 | ft_result_output_str(user, e); 40 | ft_print_result(false); 41 | memset(user, 0, sizeof(user)); 42 | close(pipefd[0]); 43 | close(pipefd[1]); 44 | return (false); 45 | } 46 | memset(user, 0, sizeof(user)); 47 | close(pipefd[0]); 48 | close(pipefd[1]); 49 | return (true); 50 | } 51 | 52 | bool ft_test_putendl_fd(char *name) 53 | { 54 | size_t i = 0, grade = 0; 55 | 56 | (void)name; 57 | while (g_str1_tests[i]) 58 | { 59 | grade += ft_run_test((char *)g_str1_tests[i], (char *)g_eputendl[i]); 60 | i++; 61 | } 62 | return (grade == i); 63 | } 64 | -------------------------------------------------------------------------------- /srcs/tests/ft_test_putnbr_fd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_test_putnbr_fd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: juperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2024/03/27 09:32:56 by juperez #+# #+# */ 9 | /* Updated: 2024/05/21 19:19:52 by juperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libtest.h" 14 | 15 | static bool ft_run_test(char *n_str) 16 | { 17 | int n = atoi(n_str); 18 | int pipefd[2]; 19 | char user[BUFFER_SIZE]; 20 | 21 | memset(user, 0, sizeof(user)); 22 | pipe(pipefd); 23 | ft_time_function(USER_START); 24 | ft_putnbr_fd(n, pipefd[1]); 25 | ft_time_function(USER_END); 26 | read(pipefd[0], user, strlen(n_str)); 27 | if (strcmp(user, n_str)) 28 | { 29 | ft_result_input_int(n); 30 | ft_result_output_str(user, n_str); 31 | ft_print_result(false); 32 | memset(user, 0, sizeof(user)); 33 | close(pipefd[0]); 34 | close(pipefd[1]); 35 | return (false); 36 | } 37 | memset(user, 0, sizeof(user)); 38 | close(pipefd[0]); 39 | close(pipefd[1]); 40 | return (true); 41 | } 42 | 43 | bool ft_test_putnbr_fd(char *name) 44 | { 45 | size_t i = 0, grade = 0; 46 | 47 | (void)name; 48 | while (g_nbr_tests[i]) 49 | { 50 | grade += ft_run_test((char *)g_nbr_tests[i]); 51 | i++; 52 | } 53 | return (grade == i); 54 | } -------------------------------------------------------------------------------- /srcs/tests/ft_test_putstr_fd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_test_putstr_fd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: juperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2024/03/27 09:32:29 by juperez #+# #+# */ 9 | /* Updated: 2024/05/21 19:06:14 by juperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libtest.h" 14 | 15 | static bool ft_run_test(char *s) 16 | { 17 | int pipefd[2]; 18 | char user[BUFFER_SIZE]; 19 | 20 | memset(user, 0, sizeof(user)); 21 | pipe(pipefd); 22 | ft_time_function(USER_START); 23 | ft_putstr_fd(s, pipefd[1]); 24 | ft_time_function(USER_END); 25 | read(pipefd[0], user, strlen(s)); 26 | if (strcmp(user, s)) 27 | { 28 | ft_result_input_str(s, NULL); 29 | ft_result_output_str(user, s); 30 | ft_print_result(false); 31 | memset(user, 0, sizeof(user)); 32 | close(pipefd[0]); 33 | close(pipefd[1]); 34 | return (false); 35 | } 36 | memset(user, 0, sizeof(user)); 37 | close(pipefd[0]); 38 | close(pipefd[1]); 39 | return (true); 40 | } 41 | 42 | bool ft_test_putstr_fd(char *name) 43 | { 44 | size_t i = 0, grade = 0; 45 | 46 | (void)name; 47 | while (g_str1_tests[i]) 48 | { 49 | grade += ft_run_test((char *)g_str1_tests[i]); 50 | i++; 51 | } 52 | return (grade == i); 53 | } 54 | -------------------------------------------------------------------------------- /srcs/tests/ft_test_split.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_test_split.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: juperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2024/03/27 09:31:37 by juperez #+# #+# */ 9 | /* Updated: 2024/03/31 13:25:18 by juperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libtest.h" 14 | 15 | const char *g_split_str[] = { 16 | " Hello World ! ", 17 | " 42 ", 18 | "42", 19 | " ", 20 | "", 21 | "a b c d e f", 22 | "abc def", 23 | NULL 24 | }; 25 | 26 | const char *g_esplit[][7] = { 27 | {"Hello", "World", "!", NULL}, 28 | {"42", NULL}, 29 | {"42", NULL}, 30 | {NULL}, 31 | {NULL}, 32 | {"a", "b", "c", "d", "e", "f", NULL}, 33 | {"abc", "def", NULL} 34 | }; 35 | 36 | static void ft_free(char **user) 37 | { 38 | for (size_t i = 0; user[i]; i++) 39 | free(user[i]); 40 | free(user); 41 | } 42 | 43 | static bool ft_check_result(char **user, char **e) 44 | { 45 | for (size_t i = 0; e[i]; i++) 46 | { 47 | if (e[i] && !user[i]) 48 | return (false); 49 | if (!e[i] && user[i]) 50 | return (false); 51 | if (e[i] && user[i] && strcmp(user[i], e[i])) 52 | return (false); 53 | } 54 | return (true); 55 | } 56 | 57 | static bool ft_run_test(char const *s, char c, char **e) 58 | { 59 | char **user; 60 | 61 | ft_time_function(USER_START); 62 | user = ft_split(s, c); 63 | ft_time_function(USER_END); 64 | if (!ft_check_result(user, e)) 65 | { 66 | ft_result_input_str((char *)s, NULL); 67 | ft_result_input_chr(c); 68 | ft_result_output_tabstr(user, e); 69 | ft_print_result(false); 70 | ft_free(user); 71 | return (false); 72 | } 73 | ft_free(user); 74 | return (true); 75 | } 76 | 77 | bool ft_test_split(char *name) 78 | { 79 | size_t i = 0, grade = 0; 80 | 81 | (void)name; 82 | while (g_split_str[i]) 83 | { 84 | grade += ft_run_test(g_split_str[i], ' ', (char **)g_esplit[i]); 85 | i++; 86 | } 87 | return (grade == i); 88 | } 89 | -------------------------------------------------------------------------------- /srcs/tests/ft_test_strchr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_test_strchr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: juperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2024/03/27 09:26:37 by juperez #+# #+# */ 9 | /* Updated: 2024/03/30 10:26:48 by juperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libtest.h" 14 | 15 | static bool ft_run_test(const char *s, int c) 16 | { 17 | char *user, *libc; 18 | 19 | ft_time_function(USER_START); 20 | user = ft_strchr(s, c); 21 | ft_time_function(USER_END_LIBC_START); 22 | libc = strchr(s, c); 23 | ft_time_function(LIBC_END); 24 | if (!(user == libc)) 25 | { 26 | ft_result_input_str((char *)s, NULL); 27 | ft_result_input_int(c); 28 | ft_result_output_str(user, libc); 29 | ft_print_result(true); 30 | return (false); 31 | } 32 | return (true); 33 | } 34 | 35 | bool ft_test_strchr(char *name) 36 | { 37 | int i = CHAR_MIN - 1, grade = CHAR_MIN - 1; 38 | 39 | (void)name; 40 | while (i <= UCHAR_MAX + 1) 41 | { 42 | grade += ft_run_test(g_str1_tests[1], i); 43 | i++; 44 | } 45 | return (grade == i); 46 | } 47 | -------------------------------------------------------------------------------- /srcs/tests/ft_test_strdup.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_test_strdup.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: juperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2024/03/15 09:49:04 by juperez #+# #+# */ 9 | /* Updated: 2024/03/30 10:26:49 by juperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libtest.h" 14 | 15 | static bool ft_run_test(const char *s) 16 | { 17 | char *user, *libc; 18 | 19 | ft_time_function(USER_START); 20 | user = ft_strdup(s); 21 | ft_time_function(USER_END_LIBC_START); 22 | libc = strdup(s); 23 | ft_time_function(LIBC_END); 24 | if (strcmp(user, libc)) 25 | { 26 | ft_result_input_str((char *)s, NULL); 27 | ft_result_output_str(user, libc); 28 | ft_print_result(true); 29 | free(user); 30 | free(libc); 31 | return (false); 32 | } 33 | free(user); 34 | free(libc); 35 | return (true); 36 | } 37 | 38 | bool ft_test_strdup(char *name) 39 | { 40 | size_t i = 0, grade = 0; 41 | 42 | (void)name; 43 | while (g_str1_tests[i]) 44 | { 45 | grade += ft_run_test(g_str1_tests[i]); 46 | i++; 47 | } 48 | return (grade == i); 49 | } 50 | -------------------------------------------------------------------------------- /srcs/tests/ft_test_striteri.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_test_striteri.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: juperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2024/03/27 09:32:05 by juperez #+# #+# */ 9 | /* Updated: 2024/05/22 01:22:56 by juperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libtest.h" 14 | 15 | char *g_striteri_str[] = { 16 | "helLO WorlD!", 17 | "abcdefghijklMNOpqrstuvwXYZ", 18 | "42", 19 | "", 20 | NULL 21 | }; 22 | 23 | const char *g_estriteri[] = { 24 | "Hello world!", 25 | "Abcdefghijklmnopqrstuvwxyz", 26 | "42", 27 | "", 28 | NULL 29 | }; 30 | 31 | static void ft_test_function(unsigned int i, char *s) 32 | { 33 | *s = i ? tolower(*s) : toupper(*s); 34 | } 35 | 36 | static bool ft_run_test(char *s, void (*f)(unsigned int, char *), char *e) 37 | { 38 | char *user; 39 | 40 | user = strdup(s); 41 | ft_time_function(USER_START); 42 | ft_striteri(user, f); 43 | ft_time_function(USER_END); 44 | if (strcmp(user, e)) 45 | { 46 | ft_result_input_str(s, NULL); 47 | ft_result_output_str(user, e); 48 | ft_print_result(false); 49 | free(user); 50 | return (false); 51 | } 52 | free(user); 53 | return (true); 54 | } 55 | 56 | bool ft_test_striteri(char *name) 57 | { 58 | size_t i = 0, grade = 0; 59 | 60 | (void)name; 61 | while (g_striteri_str[i]) 62 | { 63 | grade += ft_run_test(g_striteri_str[i], ft_test_function, (char *)g_estriteri[i]); 64 | i++; 65 | } 66 | return (grade == i); 67 | } 68 | -------------------------------------------------------------------------------- /srcs/tests/ft_test_strjoin.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_test_strjoin.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: juperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2024/03/27 09:31:09 by juperez #+# #+# */ 9 | /* Updated: 2024/05/22 01:22:40 by juperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libtest.h" 14 | 15 | const char *g_strjoin_s1[] = { 16 | "Hello", 17 | "4", 18 | "", 19 | "abc", 20 | "", 21 | NULL 22 | }; 23 | 24 | const char *g_strjoin_s2[] = { 25 | " World!", 26 | "2", 27 | "", 28 | "", 29 | "abc", 30 | NULL 31 | }; 32 | 33 | const char *g_estrjoin[] = { 34 | "Hello World!", 35 | "42", 36 | "", 37 | "abc", 38 | "abc", 39 | NULL 40 | }; 41 | 42 | static bool ft_run_test(char const *s1, char const *s2, char *e) 43 | { 44 | char *user; 45 | 46 | ft_time_function(USER_START); 47 | user = ft_strjoin(s1, s2); 48 | ft_time_function(USER_END); 49 | if (strcmp(user, e)) 50 | { 51 | ft_result_input_str((char *)s1, (char *)s2); 52 | ft_result_output_str(user, e); 53 | ft_print_result(false); 54 | free(user); 55 | return (false); 56 | } 57 | free(user); 58 | return (true); 59 | } 60 | 61 | bool ft_test_strjoin(char *name) 62 | { 63 | size_t i = 0, grade = 0; 64 | 65 | (void)name; 66 | while (g_strjoin_s1[i]) 67 | { 68 | grade += ft_run_test(g_strjoin_s1[i], g_strjoin_s2[i], (char *)g_estrjoin[i]); 69 | i++; 70 | } 71 | return (grade == i); 72 | } 73 | -------------------------------------------------------------------------------- /srcs/tests/ft_test_strlcat.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_test_strlcat.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: juperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2024/03/27 08:48:30 by juperez #+# #+# */ 9 | /* Updated: 2024/03/30 10:26:50 by juperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libtest.h" 14 | 15 | static bool ft_run_test(const char *src, size_t size) 16 | { 17 | char user_dst[] = "DEST\0............................"; 18 | char libc_dst[] = "DEST\0............................"; 19 | size_t user, libc; 20 | 21 | ft_time_function(USER_START); 22 | user = ft_strlcat(user_dst, src, size); 23 | ft_time_function(USER_END_LIBC_START); 24 | libc = strlcat(libc_dst, src, size); 25 | ft_time_function(LIBC_END); 26 | if (strcmp(user_dst, libc_dst) && !(user == libc)) 27 | { 28 | ft_result_input_sizet(size); 29 | ft_result_input_str((char *)src, NULL); 30 | ft_result_output_sizet(user, libc); 31 | ft_result_output_str(user_dst, libc_dst); 32 | ft_print_result(true); 33 | return (false); 34 | } 35 | return (true); 36 | } 37 | 38 | bool ft_test_strlcat(char *name) 39 | { 40 | size_t size[] = {0, 1, 2, 4, 8, 16, 32}; 41 | size_t i = 0, grade = 0, count = sizeof(size) / sizeof(size[0]); 42 | 43 | (void)name; 44 | while (i < count) 45 | { 46 | grade += ft_run_test(g_str1_tests[1], size[i]); 47 | i++; 48 | } 49 | return (grade == i); 50 | } 51 | -------------------------------------------------------------------------------- /srcs/tests/ft_test_strlcpy.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_test_strlcpy.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: juperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2024/03/27 09:25:46 by juperez #+# #+# */ 9 | /* Updated: 2024/03/30 10:26:52 by juperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libtest.h" 14 | 15 | static bool ft_run_test(const char *src, size_t size) 16 | { 17 | char user_dst[] = "................"; 18 | char libc_dst[] = "................"; 19 | size_t user, libc; 20 | 21 | ft_time_function(USER_START); 22 | user = ft_strlcpy(user_dst, src, size); 23 | ft_time_function(USER_END_LIBC_START); 24 | libc = strlcpy(libc_dst, src, size); 25 | ft_time_function(LIBC_END); 26 | if (strcmp(user_dst, libc_dst) && !(user == libc)) 27 | { 28 | ft_result_input_sizet(size); 29 | ft_result_input_str((char *)src, NULL); 30 | ft_result_output_sizet(user, libc); 31 | ft_result_output_str(user_dst, libc_dst); 32 | ft_print_result(true); 33 | return (false); 34 | } 35 | return (true); 36 | } 37 | 38 | bool ft_test_strlcpy(char *name) 39 | { 40 | size_t i = 0, grade = 0; 41 | 42 | (void)name; 43 | while (i < 16) 44 | { 45 | grade += ft_run_test(g_str1_tests[1], i); 46 | i++; 47 | } 48 | return (grade == i); 49 | } 50 | -------------------------------------------------------------------------------- /srcs/tests/ft_test_strlen.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_test_strlen.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: juperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2024/03/15 09:42:04 by juperez #+# #+# */ 9 | /* Updated: 2024/03/30 10:26:53 by juperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libtest.h" 14 | 15 | static bool ft_run_test(const char *s) 16 | { 17 | size_t user, libc; 18 | 19 | ft_time_function(USER_START); 20 | user = ft_strlen(s); 21 | ft_time_function(USER_END_LIBC_START); 22 | libc = strlen(s); 23 | ft_time_function(LIBC_END); 24 | if (!(user == libc)) 25 | { 26 | ft_result_input_str((char *)s, NULL); 27 | ft_result_output_sizet(user, libc); 28 | ft_print_result(true); 29 | return (false); 30 | } 31 | return (true); 32 | } 33 | 34 | bool ft_test_strlen(char *name) 35 | { 36 | size_t i = 0, grade = 0; 37 | 38 | (void)name; 39 | while (g_str1_tests[i]) 40 | { 41 | grade += ft_run_test(g_str1_tests[i]); 42 | i++; 43 | } 44 | return (grade == i); 45 | } 46 | -------------------------------------------------------------------------------- /srcs/tests/ft_test_strmapi.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_test_strmapi.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: juperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2024/03/27 09:31:51 by juperez #+# #+# */ 9 | /* Updated: 2024/05/22 01:22:26 by juperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libtest.h" 14 | 15 | const char *g_strmapi_str[] = { 16 | "helLO WorlD!", 17 | "abcdefghijklMNOpqrstuvwXYZ", 18 | "42", 19 | "", 20 | NULL 21 | }; 22 | 23 | const char *g_estrmapi[] = { 24 | "Hello world!", 25 | "Abcdefghijklmnopqrstuvwxyz", 26 | "42", 27 | "", 28 | NULL 29 | }; 30 | 31 | static char ft_test_function(unsigned int i, char c) 32 | { 33 | return (i ? tolower(c) : toupper(c)); 34 | } 35 | 36 | static bool ft_run_test(char const *s, char (*f)(unsigned int, char), char *e) 37 | { 38 | char *user; 39 | 40 | ft_time_function(USER_START); 41 | user = ft_strmapi(s, f); 42 | ft_time_function(USER_END); 43 | if (strcmp(user, e)) 44 | { 45 | ft_result_input_str((char *)s, NULL); 46 | ft_result_output_str(user, e); 47 | ft_print_result(false); 48 | free(user); 49 | return (false); 50 | } 51 | free(user); 52 | return (true); 53 | } 54 | 55 | bool ft_test_strmapi(char *name) 56 | { 57 | size_t i = 0, grade = 0; 58 | 59 | (void)name; 60 | while (g_strmapi_str[i]) 61 | { 62 | grade += ft_run_test(g_strmapi_str[i], ft_test_function, (char *)g_estrmapi[i]); 63 | i++; 64 | } 65 | return (grade == i); 66 | } 67 | -------------------------------------------------------------------------------- /srcs/tests/ft_test_strncmp.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_test_strncmp.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: juperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2024/03/27 09:27:51 by juperez #+# #+# */ 9 | /* Updated: 2024/03/30 10:26:54 by juperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libtest.h" 14 | 15 | static bool ft_run_test(const char *s1, const char *s2, size_t n) 16 | { 17 | int user, libc; 18 | 19 | ft_time_function(USER_START); 20 | user = ft_strncmp(s1, s2, n); 21 | ft_time_function(USER_END_LIBC_START); 22 | libc = strncmp(s1, s2, n); 23 | ft_time_function(LIBC_END); 24 | if (!(user == libc)) 25 | { 26 | ft_result_input_sizet(n); 27 | ft_result_input_str((char *)s1, (char *)s2); 28 | ft_result_output_int(user, libc); 29 | ft_print_result(true); 30 | return (false); 31 | } 32 | return (true); 33 | } 34 | 35 | static bool ft_test_size(const char *s1, const char *s2) 36 | { 37 | size_t i = 0, grade = 0; 38 | 39 | while (i < 30) 40 | { 41 | grade += ft_run_test(s1, s2, i); 42 | i++; 43 | } 44 | return (grade == i); 45 | } 46 | 47 | static bool ft_test_str2(const char *s1) 48 | { 49 | size_t i = 0, grade = 0; 50 | 51 | while (g_str2_tests[i]) 52 | { 53 | grade += ft_test_size(s1, g_str2_tests[i]); 54 | i++; 55 | } 56 | return (grade == i); 57 | } 58 | 59 | bool ft_test_strncmp(char *name) 60 | { 61 | size_t i = 0, grade = 0; 62 | 63 | (void)name; 64 | while (g_str1_tests[i]) 65 | { 66 | grade += ft_test_str2(g_str1_tests[i]); 67 | i++; 68 | } 69 | return (grade == i); 70 | } 71 | -------------------------------------------------------------------------------- /srcs/tests/ft_test_strnstr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_test_strnstr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: juperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2024/03/27 09:30:29 by juperez #+# #+# */ 9 | /* Updated: 2024/03/30 10:26:56 by juperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libtest.h" 14 | 15 | static bool ft_run_test(const char *str, const char *to_find, size_t len) 16 | { 17 | char *user, *libc; 18 | 19 | ft_time_function(USER_START); 20 | user = ft_strnstr(str, to_find, len); 21 | ft_time_function(USER_END_LIBC_START); 22 | libc = strnstr(str, to_find, len); 23 | ft_time_function(LIBC_END); 24 | if (!(user == libc)) 25 | { 26 | ft_result_input_sizet(len); 27 | ft_result_input_str((char *)str, (char *)to_find); 28 | ft_result_output_str(user, libc); 29 | ft_print_result(true); 30 | return (false); 31 | } 32 | return (true); 33 | } 34 | 35 | static bool ft_test_size(const char *str, const char *to_find) 36 | { 37 | size_t i = 0, grade = 0; 38 | 39 | while (i < 30) 40 | { 41 | grade += ft_run_test(str, to_find, i); 42 | i++; 43 | } 44 | return (grade == i); 45 | } 46 | 47 | static bool ft_test_tofind(const char *str) 48 | { 49 | size_t i = 0, grade = 0; 50 | 51 | while (g_str2_tests[i]) 52 | { 53 | grade += ft_test_size(str, g_str2_tests[i]); 54 | i++; 55 | } 56 | return (grade == i); 57 | } 58 | 59 | bool ft_test_strnstr(char *name) 60 | { 61 | size_t i = 0, grade = 0; 62 | 63 | (void)name; 64 | while (g_str1_tests[i]) 65 | { 66 | grade += ft_test_tofind(g_str1_tests[i]); 67 | i++; 68 | } 69 | return (grade == i); 70 | } 71 | -------------------------------------------------------------------------------- /srcs/tests/ft_test_strrchr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_test_strrchr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: juperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2024/03/27 09:27:27 by juperez #+# #+# */ 9 | /* Updated: 2024/03/30 10:26:57 by juperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libtest.h" 14 | 15 | static bool ft_run_test(const char *s, int c) 16 | { 17 | char *user, *libc; 18 | 19 | ft_time_function(USER_START); 20 | user = ft_strrchr(s, c); 21 | ft_time_function(USER_END_LIBC_START); 22 | libc = strrchr(s, c); 23 | ft_time_function(LIBC_END); 24 | if (!(user == libc)) 25 | { 26 | ft_result_input_str((char *)s, NULL); 27 | ft_result_input_int(c); 28 | ft_result_output_str(user, libc); 29 | ft_print_result(true); 30 | return (true); 31 | } 32 | return (true); 33 | } 34 | 35 | bool ft_test_strrchr(char *name) 36 | { 37 | int i = CHAR_MIN - 1, grade = CHAR_MIN - 1; 38 | 39 | (void)name; 40 | while (i <= UCHAR_MAX + 1) 41 | { 42 | grade += ft_run_test(g_str1_tests[1], i); 43 | i++; 44 | } 45 | return (grade == i); 46 | } 47 | -------------------------------------------------------------------------------- /srcs/tests/ft_test_strtrim.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_test_strtrim.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: juperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2024/03/27 09:31:22 by juperez #+# #+# */ 9 | /* Updated: 2024/05/22 01:22:12 by juperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libtest.h" 14 | 15 | const char *g_strtrim_s1[] = { 16 | " Hello World! ", 17 | "eeeHello World!ooo", 18 | "Hello World!ooo", 19 | "eeeHello World!", 20 | "42", 21 | "", 22 | NULL 23 | }; 24 | 25 | const char *g_strtrim_set[] = { 26 | " ", 27 | "eo", 28 | "eo", 29 | "eo", 30 | "", 31 | "42", 32 | NULL 33 | }; 34 | 35 | const char *g_estrtrim[] = { 36 | "Hello World!", 37 | "Hello World!", 38 | "Hello World!", 39 | "Hello World!", 40 | "42", 41 | "", 42 | NULL 43 | }; 44 | 45 | static bool ft_run_test(char const *s1, char const *set, char *e) 46 | { 47 | char *user; 48 | 49 | ft_time_function(USER_START); 50 | user = ft_strtrim(s1, set); 51 | ft_time_function(USER_END); 52 | if (strcmp(user, e)) 53 | { 54 | ft_result_input_str((char *)s1, (char *)set); 55 | ft_result_output_str(user, e); 56 | ft_print_result(false); 57 | free(user); 58 | return (false); 59 | } 60 | free(user); 61 | return (true); 62 | } 63 | 64 | bool ft_test_strtrim(char *name) 65 | { 66 | size_t i = 0, grade = 0; 67 | 68 | (void)name; 69 | while (g_strtrim_s1[i]) 70 | { 71 | grade += ft_run_test(g_strtrim_s1[i], g_strtrim_set[i], (char *)g_estrtrim[i]); 72 | i++; 73 | } 74 | return (grade == i); 75 | } 76 | -------------------------------------------------------------------------------- /srcs/tests/ft_test_substr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_test_substr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: juperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2024/03/27 09:30:55 by juperez #+# #+# */ 9 | /* Updated: 2024/05/22 01:22:06 by juperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libtest.h" 14 | 15 | const char *g_esubstr[] = { 16 | "Hello", 17 | "Hello World!", 18 | "World!", 19 | "World!", 20 | "!", 21 | " ", 22 | "", 23 | NULL, 24 | }; 25 | 26 | static bool ft_run_test(char const *s, unsigned int start, size_t len, char *e) 27 | { 28 | char *user; 29 | 30 | ft_time_function(USER_START); 31 | user = ft_substr(s, start, len); 32 | ft_time_function(USER_END); 33 | if (strcmp(user, e)) 34 | { 35 | ft_result_input_str((char *)s, NULL); 36 | ft_result_input_int((int)start); 37 | ft_result_input_sizet(len); 38 | ft_result_output_str(user, e); 39 | ft_print_result(false); 40 | free(user); 41 | return (false); 42 | } 43 | free(user); 44 | return (true); 45 | } 46 | 47 | bool ft_test_substr(char *name) 48 | { 49 | unsigned int start[] = {0, 0, 6, 6, 11, 5, 0}; 50 | size_t len[] = {5, 15, 6, 15, 1, 1, 0}; 51 | size_t i = 0, grade = 0; 52 | 53 | (void)name; 54 | while (g_esubstr[i]) 55 | { 56 | grade += ft_run_test(g_str1_tests[1], start[i], len[i], (char *)g_esubstr[i]); 57 | i++; 58 | } 59 | return (grade == i); 60 | } 61 | -------------------------------------------------------------------------------- /srcs/utils/ft_print_test.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_print_test.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: juperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2024/03/18 09:19:55 by juperez #+# #+# */ 9 | /* Updated: 2024/03/31 12:30:53 by juperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libtest.h" 14 | 15 | static void ft_putchar_isprint(char c) 16 | { 17 | printf("%s'", DM); 18 | if (isprint(c)) 19 | printf("%c", c); 20 | else 21 | printf("\\%02x", (unsigned char)c); 22 | printf("'%s ", X); 23 | } 24 | 25 | static void ft_putstr_isprint(char *str) 26 | { 27 | if (!str) 28 | printf("%sNULL%s ", DM, X); 29 | else 30 | { 31 | printf("%s\"", DM); 32 | while (*str) 33 | { 34 | if (isprint(*str)) 35 | printf("%c", *str); 36 | else 37 | printf("\\%02x", (unsigned char)*str); 38 | str++; 39 | } 40 | printf("\"%s ", X); 41 | } 42 | } 43 | 44 | static void ft_puttabstr(char **str) 45 | { 46 | if (!*str) 47 | ft_putstr_isprint(*str); 48 | else 49 | { 50 | for (size_t i = 0; str[i]; i++) 51 | { 52 | ft_putstr_isprint(str[i]); 53 | printf(" "); 54 | } 55 | } 56 | } 57 | 58 | static void ft_print_intput(void) 59 | { 60 | printf("%s", INPUT); 61 | if (g_presult.input_int) 62 | printf("%s%i%s ", DM, g_result.input_int, X); 63 | if (g_presult.input_sizet) 64 | printf("%s%zu%s ", DM, g_result.input_sizet, X); 65 | if (g_presult.input_chr) 66 | ft_putchar_isprint(g_result.input_chr); 67 | if (g_presult.input_str1) 68 | ft_putstr_isprint(g_result.input_str1); 69 | if (g_presult.input_str2) 70 | ft_putstr_isprint(g_result.input_str2); 71 | printf("\n"); 72 | } 73 | 74 | static void ft_print_output_user(bool print_libc) 75 | { 76 | printf("%s%s%s", OUTPUT, USER, print_libc ? "" : " "); 77 | if (g_presult.output_int) 78 | printf("%s%i%s ", DM, g_result.user_int, X); 79 | if (g_presult.output_sizet) 80 | printf("%s%zu%s ", DM, g_result.user_sizet, X); 81 | if (g_presult.output_chr) 82 | ft_putchar_isprint(g_result.user_chr); 83 | if (g_presult.output_str) 84 | ft_putstr_isprint(g_result.user_str); 85 | if (g_presult.output_tabstr) 86 | ft_puttabstr(g_result.user_tabstr); 87 | } 88 | 89 | static void ft_print_output_libc(bool print_libc) 90 | { 91 | printf("\n\t\t %s", print_libc ? LIBC : EXPECT); 92 | if (g_presult.output_int) 93 | printf("%s%i%s ", DM, g_result.libc_int, X); 94 | if (g_presult.output_sizet) 95 | printf("%s%zu%s ", DM, g_result.libc_sizet, X); 96 | if (g_presult.output_chr) 97 | ft_putchar_isprint(g_result.libc_chr); 98 | if (g_presult.output_str) 99 | ft_putstr_isprint(g_result.libc_str); 100 | if (g_presult.output_tabstr) 101 | ft_puttabstr(g_result.libc_tabstr); 102 | } 103 | 104 | void ft_print_result(bool print_libc) 105 | { 106 | printf("%s%s", TEST, KO); 107 | ft_print_intput(); 108 | ft_print_output_user(print_libc); 109 | ft_print_output_libc(print_libc); 110 | printf("\n"); 111 | } 112 | 113 | void ft_reset_presult(void) 114 | { 115 | g_presult.input_int = false; 116 | g_presult.input_sizet = false; 117 | g_presult.input_chr = false; 118 | g_presult.input_str1 = false; 119 | g_presult.input_str2 = false; 120 | g_presult.output_int = false; 121 | g_presult.output_sizet = false; 122 | g_presult.output_chr = false; 123 | g_presult.output_str = false; 124 | g_presult.output_tabstr = false; 125 | } 126 | 127 | void ft_result_input_int(int intput) 128 | { 129 | g_result.input_int = intput; 130 | g_presult.input_int = true; 131 | } 132 | 133 | void ft_result_input_sizet(size_t intput) 134 | { 135 | g_result.input_sizet = intput; 136 | g_presult.input_sizet = true; 137 | } 138 | 139 | void ft_result_input_chr(char intput) 140 | { 141 | g_result.input_chr = intput; 142 | g_presult.input_chr = true; 143 | } 144 | 145 | void ft_result_input_str(char *str1, char *str2) 146 | { 147 | if (str1) 148 | { 149 | g_result.input_str1 = str1; 150 | g_presult.input_str1 = true; 151 | } 152 | if (str2) 153 | { 154 | g_result.input_str2 = str2; 155 | g_presult.input_str2 = true; 156 | } 157 | } 158 | 159 | void ft_result_output_int(int user, int libc) 160 | { 161 | g_result.user_int = user; 162 | g_result.libc_int = libc; 163 | g_presult.output_int = true; 164 | } 165 | 166 | void ft_result_output_sizet(size_t user, size_t libc) 167 | { 168 | g_result.user_sizet = user; 169 | g_result.libc_sizet = libc; 170 | g_presult.output_sizet = true; 171 | } 172 | 173 | void ft_result_output_chr(char user, char libc) 174 | { 175 | g_result.user_chr = user; 176 | g_result.libc_chr = libc; 177 | g_presult.output_chr = true; 178 | } 179 | 180 | void ft_result_output_str(char *user, char *libc) 181 | { 182 | g_result.user_str = user; 183 | g_result.libc_str = libc; 184 | g_presult.output_str = true; 185 | } 186 | 187 | void ft_result_output_tabstr(char **user, char **libc) 188 | { 189 | g_result.user_tabstr = user; 190 | g_result.libc_tabstr = libc; 191 | g_presult.output_tabstr = true; 192 | } 193 | 194 | void ft_grade(bool success) 195 | { 196 | if (success) 197 | { 198 | printf("%s%s", TEST, OK); 199 | ft_time_function(PRINT); 200 | } 201 | printf("%s%s", GRADE, success ? SUCCESS : FAIL); 202 | } 203 | -------------------------------------------------------------------------------- /srcs/utils/ft_utils.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_utils.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: juperez +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2024/03/15 08:26:25 by juperez #+# #+# */ 9 | /* Updated: 2024/05/22 15:45:35 by juperez ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libtest.h" 14 | 15 | static bool ft_build_cmd(char *target, size_t len, char *cmd_start, char *cmd_end) 16 | { 17 | char *cmd; 18 | size_t cmd_len; 19 | bool success; 20 | 21 | cmd = NULL; 22 | cmd_len = strlen(cmd_start) + len + strlen(cmd_end); 23 | success = false; 24 | cmd = (char *)malloc(sizeof(char) * cmd_len + 1); 25 | if (!cmd) 26 | { 27 | fprintf(stderr, ERROR_MEM); 28 | exit(EXIT_FAILURE); 29 | } 30 | cmd[cmd_len] = '\0'; 31 | snprintf(cmd, cmd_len + 1, "%s%s%s", cmd_start, target, cmd_end); 32 | success = (system(cmd)); 33 | free(cmd); 34 | return (success); 35 | } 36 | 37 | void ft_print_name(char *name) 38 | { 39 | int len; 40 | int space; 41 | 42 | len = strlen(name); 43 | space = (SIZE_LINE - len - 2) / 2; 44 | printf("%.*s %s%s%s%s %.*s\n", space, LINE, B, BD, name, X, SIZE_LINE - space - len, LINE); 45 | } 46 | 47 | void ft_print_file(char *path) 48 | { 49 | FILE *file; 50 | char buffer[BUFFER_SIZE]; 51 | size_t read; 52 | 53 | file = fopen(path, "r"); 54 | if (!file) 55 | return ; 56 | while ((read = fread(buffer, 1, BUFFER_SIZE, file)) > 0) 57 | fwrite(buffer, 1, read, stdout); 58 | fclose(file); 59 | } 60 | 61 | bool ft_test_norminette(char *name) 62 | { 63 | size_t len; 64 | bool success; 65 | bool version_last = (system(CMD_NV)); 66 | 67 | len = strlen(name); 68 | success = ft_build_cmd(name, len, CMD_NS, CMD_NE); 69 | success = !version_last ? success ? false : true : success; 70 | printf("%s%s", NORME, success ? OK : ERROR); 71 | if (!success) 72 | printf("%s%s", GRADE, FAIL); 73 | return (success); 74 | } 75 | 76 | bool ft_check_sysfunc(char *name) 77 | { 78 | bool success; 79 | 80 | success = ft_build_cmd(name, strlen(name), CMD_CS, CMD_CE); 81 | printf("%s%s", FOR_FUNC, success ? OK : CHEAT); 82 | if (!success) 83 | printf("%s%s", GRADE, GRADE_CHEAT); 84 | return (success); 85 | } 86 | 87 | void ft_time_function(t_ftime action) 88 | { 89 | static bool print_libc; 90 | static clock_t user_start, libc_start; 91 | static double user_time, libc_time; 92 | 93 | if (action == USER_END_LIBC_START) 94 | print_libc = true; 95 | else if (action == USER_END) 96 | print_libc = false; 97 | if (action == RESET) 98 | { 99 | user_time = 0; 100 | libc_time = 0; 101 | } 102 | if (action == USER_START) 103 | user_start = clock(); 104 | if ((action == USER_END) || (action == USER_END_LIBC_START)) 105 | user_time += ((double)(clock() - user_start)) / CLOCKS_PER_SEC; 106 | if ((action == LIBC_START) || (action == USER_END_LIBC_START)) 107 | libc_start = clock(); 108 | if (action == LIBC_END) 109 | libc_time += ((double)(clock() - libc_start)) / CLOCKS_PER_SEC; 110 | if (action == PRINT) 111 | { 112 | printf("%s%s%s%fs%s", TIME, USER, DM, user_time, X); 113 | if (print_libc) 114 | printf(" | %s%s%fs%s", LIBC, DM, libc_time, X); 115 | printf("\n"); 116 | user_time = 0; 117 | libc_time = 0; 118 | } 119 | } 120 | 121 | void ft_free_lst(t_list *lst) 122 | { 123 | t_list *tmp; 124 | 125 | while (lst) 126 | { 127 | tmp = lst->next; 128 | free(lst); 129 | lst = tmp; 130 | } 131 | } 132 | 133 | size_t ft_lst_size(t_list *lst) 134 | { 135 | size_t size = 0; 136 | 137 | while (lst) 138 | { 139 | lst = lst->next; 140 | size++; 141 | } 142 | return (size); 143 | } 144 | 145 | void ft_test_free(void *ptr) 146 | { 147 | free(ptr); 148 | g_node_freed = 1; 149 | } 150 | 151 | void ft_strtoupper(void *ptr) 152 | { 153 | char *str = (char *)ptr; 154 | 155 | for (size_t i = 0; str[i]; i++) 156 | str[i] = toupper(str[i]); 157 | } 158 | 159 | void *ft_duptoupper(void *ptr) 160 | { 161 | char *str = strdup((char *)ptr); 162 | 163 | for (size_t i = 0; str[i]; i++) 164 | str[i] = toupper(str[i]); 165 | return ((void *)str); 166 | } --------------------------------------------------------------------------------