From 51964b301b84bb01fdee6940a8583a8656d8a01f Mon Sep 17 00:00:00 2001 From: Tom Damerose <50496792+tdameros@users.noreply.github.com> Date: Sat, 6 Apr 2024 00:46:49 +0200 Subject: [PATCH] add google code-style (#2) * add google code-style * fix github action --- .clang-format | 226 +++++++++++++++++++++++++++++++++++++ .github/workflows/main.yml | 5 +- Makefile | 12 +- include/libasm.h | 2 + test/ft_read.c | 192 +++++++++++++++---------------- test/ft_strcmp.c | 72 ++++++------ test/ft_strcpy.c | 63 +++++------ test/ft_strdup.c | 44 ++++---- test/ft_strlen.c | 18 +-- test/ft_write.c | 152 ++++++++++++------------- 10 files changed, 511 insertions(+), 275 deletions(-) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..b1392af --- /dev/null +++ b/.clang-format @@ -0,0 +1,226 @@ +--- +Language: Cpp +# BasedOnStyle: Google +AccessModifierOffset: -1 +AlignAfterOpenBracket: Align +AlignArrayOfStructures: None +AlignConsecutiveMacros: None +AlignConsecutiveAssignments: None +AlignConsecutiveBitFields: None +AlignConsecutiveDeclarations: None +AlignEscapedNewlines: Left +AlignOperands: Align +AlignTrailingComments: true +AllowAllArgumentsOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortEnumsOnASingleLine: true +AllowShortBlocksOnASingleLine: Never +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: All +AllowShortLambdasOnASingleLine: All +AllowShortIfStatementsOnASingleLine: WithoutElse +AllowShortLoopsOnASingleLine: true +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: true +AlwaysBreakTemplateDeclarations: Yes +AttributeMacros: + - __capability +BinPackArguments: true +BinPackParameters: true +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: Never + AfterEnum: false + AfterFunction: false + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + BeforeLambdaBody: false + BeforeWhile: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakBeforeBinaryOperators: None +BreakBeforeConceptDeclarations: true +BreakBeforeBraces: Attach +BreakBeforeInheritanceComma: false +BreakInheritanceList: BeforeColon +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: false +BreakConstructorInitializers: BeforeColon +BreakAfterJavaFieldAnnotations: false +BreakStringLiterals: true +ColumnLimit: 80 +CommentPragmas: '^ IWYU pragma:' +QualifierAlignment: Leave +CompactNamespaces: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DeriveLineEnding: true +DerivePointerAlignment: true +DisableFormat: false +EmptyLineAfterAccessModifier: Never +EmptyLineBeforeAccessModifier: LogicalBlock +ExperimentalAutoDetectBinPacking: false +PackConstructorInitializers: NextLine +BasedOnStyle: '' +ConstructorInitializerAllOnOneLineOrOnePerLine: false +AllowAllConstructorInitializersOnNextLine: true +FixNamespaceComments: true +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IfMacros: + - KJ_IF_MAYBE +IncludeBlocks: Regroup +IncludeCategories: + - Regex: '^' + Priority: 2 + SortPriority: 0 + CaseSensitive: false + - Regex: '^<.*\.h>' + Priority: 1 + SortPriority: 0 + CaseSensitive: false + - Regex: '^<.*' + Priority: 2 + SortPriority: 0 + CaseSensitive: false + - Regex: '.*' + Priority: 3 + SortPriority: 0 + CaseSensitive: false +IncludeIsMainRegex: '([-_](test|unittest))?$' +IncludeIsMainSourceRegex: '' +IndentAccessModifiers: false +IndentCaseLabels: true +IndentCaseBlocks: false +IndentGotoLabels: true +IndentPPDirectives: None +IndentExternBlock: AfterExternBlock +IndentRequires: false +IndentWidth: 2 +IndentWrappedFunctionNames: false +InsertTrailingCommas: None +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: false +LambdaBodyIndentation: Signature +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCBinPackProtocolList: Never +ObjCBlockIndentWidth: 2 +ObjCBreakBeforeNestedBlockParam: true +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 1 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakOpenParenthesis: 0 +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 200 +PenaltyIndentedWhitespace: 0 +PointerAlignment: Left +PPIndentWidth: -1 +RawStringFormats: + - Language: Cpp + Delimiters: + - cc + - CC + - cpp + - Cpp + - CPP + - 'c++' + - 'C++' + CanonicalDelimiter: '' + BasedOnStyle: google + - Language: TextProto + Delimiters: + - pb + - PB + - proto + - PROTO + EnclosingFunctions: + - EqualsProto + - EquivToProto + - PARSE_PARTIAL_TEXT_PROTO + - PARSE_TEST_PROTO + - PARSE_TEXT_PROTO + - ParseTextOrDie + - ParseTextProtoOrDie + - ParseTestProto + - ParsePartialTestProto + CanonicalDelimiter: pb + BasedOnStyle: google +ReferenceAlignment: Pointer +ReflowComments: true +RemoveBracesLLVM: false +SeparateDefinitionBlocks: Leave +ShortNamespaceLines: 1 +SortIncludes: CaseSensitive +SortJavaStaticImport: Before +SortUsingDeclarations: true +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeCaseColon: false +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeParensOptions: + AfterControlStatements: true + AfterForeachMacros: true + AfterFunctionDefinitionName: false + AfterFunctionDeclarationName: false + AfterIfMacros: true + AfterOverloadedOperator: false + BeforeNonEmptyParentheses: false +SpaceAroundPointerQualifiers: Default +SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyBlock: false +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 2 +SpacesInAngles: Never +SpacesInConditionalStatement: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInLineCommentPrefix: + Minimum: 1 + Maximum: -1 +SpacesInParentheses: false +SpacesInSquareBrackets: false +SpaceBeforeSquareBrackets: false +BitFieldColonSpacing: Both +Standard: Auto +StatementAttributeLikeMacros: + - Q_EMIT +StatementMacros: + - Q_UNUSED + - QT_REQUIRE_VERSION +TabWidth: 8 +UseCRLF: false +UseTab: Never +WhitespaceSensitiveMacros: + - STRINGIZE + - PP_STRINGIZE + - BOOST_PP_STRINGIZE + - NS_SWIFT_NAME + - CF_SWIFT_NAME +... + diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f9ec792..9b37eb7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -15,7 +15,10 @@ jobs: - uses: actions/checkout@v4 - name: Install dependencies - run: sudo apt install nasm -y + run: sudo apt-get update && sudo apt-get install -y nasm clang-format + + - name: Check format + run: make check-format - name: Build run: make diff --git a/Makefile b/Makefile index 3fe9dda..fcac310 100644 --- a/Makefile +++ b/Makefile @@ -67,7 +67,7 @@ tests: $(TEST_NAME) ./$(TEST_NAME) $(TEST_NAME): $(TEST_OBJ) $(NAME) - $(CC) $(CFLAGS) $(TEST_OBJ) $(NAME) -o $(TEST_NAME) + $(CC) $(CFLAGS) $(TEST_OBJ) -L. -l:$(NAME) -o $(TEST_NAME) # ---------- VARIABLES RULES ---------- # @@ -96,4 +96,12 @@ fclean: clean .PHONY: re re: fclean - $(MAKE) all \ No newline at end of file + $(MAKE) all + +.PHONY: check-format +check-format: + clang-format -style=file $(TEST_SRC) -n --Werror + +.PHONY: format +format: + clang-format -style=file $(TEST_SRC) -i diff --git a/include/libasm.h b/include/libasm.h index 1edc5f5..999d539 100644 --- a/include/libasm.h +++ b/include/libasm.h @@ -13,6 +13,8 @@ #ifndef LIBASM_BUILD_INCLUDE_LIBASM_H_ # define LIBASM_BUILD_INCLUDE_LIBASM_H_ +# include + ssize_t ft_read(int fd, void *buf, size_t count); int ft_strcmp(const char *s1, const char *s2); char *ft_strcpy(char *dst, const char *src); diff --git a/test/ft_read.c b/test/ft_read.c index d0237e2..9c41263 100644 --- a/test/ft_read.c +++ b/test/ft_read.c @@ -12,130 +12,130 @@ #include -#include "utest.h" #include "libasm.h" +#include "utest.h" UTEST(ft_read, empty_string) { - char s[] = ""; - int fds[2]; - ASSERT_NE_MSG(pipe(fds), -1, "pipe() failed"); - ASSERT_NE_MSG(write(fds[1], s, sizeof(s)), -1, "write() failed"); - errno = 0; - char buf[100]; - ssize_t return_code = ft_read(fds[0], buf, sizeof(s)); - ASSERT_GE(return_code, 0); - ASSERT_EQ((size_t)return_code, sizeof(s)); - ASSERT_EQ(errno, 0); - ASSERT_STREQ(s, buf); + char s[] = ""; + int fds[2]; + ASSERT_NE_MSG(pipe(fds), -1, "pipe() failed"); + ASSERT_NE_MSG(write(fds[1], s, sizeof(s)), -1, "write() failed"); + errno = 0; + char buf[100]; + ssize_t return_code = ft_read(fds[0], buf, sizeof(s)); + ASSERT_GE(return_code, 0); + ASSERT_EQ((size_t)return_code, sizeof(s)); + ASSERT_EQ(errno, 0); + ASSERT_STREQ(s, buf); } UTEST(ft_read, simple_string) { - char s[] = "1"; - int fds[2]; - ASSERT_NE_MSG(pipe(fds), -1, "pipe() failed"); - ASSERT_NE_MSG(write(fds[1], s, sizeof(s)), -1, "write() failed"); - errno = 0; - char buf[100]; - ssize_t return_code = ft_read(fds[0], buf, sizeof(s)); - ASSERT_GE(return_code, 0); - ASSERT_EQ((size_t)return_code, sizeof(s)); - ASSERT_EQ(errno, 0); - ASSERT_STREQ(s, buf); + char s[] = "1"; + int fds[2]; + ASSERT_NE_MSG(pipe(fds), -1, "pipe() failed"); + ASSERT_NE_MSG(write(fds[1], s, sizeof(s)), -1, "write() failed"); + errno = 0; + char buf[100]; + ssize_t return_code = ft_read(fds[0], buf, sizeof(s)); + ASSERT_GE(return_code, 0); + ASSERT_EQ((size_t)return_code, sizeof(s)); + ASSERT_EQ(errno, 0); + ASSERT_STREQ(s, buf); } UTEST(ft_read, odd_string) { - char s[] = "something"; - int fds[2]; - ASSERT_NE_MSG(pipe(fds), -1, "pipe() failed"); - ASSERT_NE_MSG(write(fds[1], s, sizeof(s)), -1, "write() failed"); - errno = 0; - char buf[100]; - ssize_t return_code = ft_read(fds[0], buf, sizeof(s)); - ASSERT_GE(return_code, 0); - ASSERT_EQ((size_t)return_code, sizeof(s)); - ASSERT_EQ(errno, 0); - ASSERT_STREQ(s, buf); + char s[] = "something"; + int fds[2]; + ASSERT_NE_MSG(pipe(fds), -1, "pipe() failed"); + ASSERT_NE_MSG(write(fds[1], s, sizeof(s)), -1, "write() failed"); + errno = 0; + char buf[100]; + ssize_t return_code = ft_read(fds[0], buf, sizeof(s)); + ASSERT_GE(return_code, 0); + ASSERT_EQ((size_t)return_code, sizeof(s)); + ASSERT_EQ(errno, 0); + ASSERT_STREQ(s, buf); } UTEST(ft_read, even_string) { - char s[] = "something1"; - int fds[2]; - ASSERT_NE_MSG(pipe(fds), -1, "pipe() failed"); - ASSERT_NE_MSG(write(fds[1], s, sizeof(s)), -1, "write() failed"); - errno = 0; - char buf[100]; - ssize_t return_code = ft_read(fds[0], buf, sizeof(s)); - ASSERT_GE(return_code, 0); - ASSERT_EQ((size_t)return_code, sizeof(s)); - ASSERT_EQ(errno, 0); - ASSERT_STREQ(s, buf); + char s[] = "something1"; + int fds[2]; + ASSERT_NE_MSG(pipe(fds), -1, "pipe() failed"); + ASSERT_NE_MSG(write(fds[1], s, sizeof(s)), -1, "write() failed"); + errno = 0; + char buf[100]; + ssize_t return_code = ft_read(fds[0], buf, sizeof(s)); + ASSERT_GE(return_code, 0); + ASSERT_EQ((size_t)return_code, sizeof(s)); + ASSERT_EQ(errno, 0); + ASSERT_STREQ(s, buf); } UTEST(ft_read, long_string) { - char s[] = "This is a long string with a lot of characters"; - int fds[2]; - ASSERT_NE_MSG(pipe(fds), -1, "pipe() failed"); - ASSERT_NE_MSG(write(fds[1], s, sizeof(s)), -1, "write() failed"); - errno = 0; - char buf[100]; - ssize_t return_code = ft_read(fds[0], buf, sizeof(s)); - ASSERT_GE(return_code, 0); - ASSERT_EQ((size_t)return_code, sizeof(s)); - ASSERT_EQ(errno, 0); - ASSERT_STREQ(s, buf); + char s[] = "This is a long string with a lot of characters"; + int fds[2]; + ASSERT_NE_MSG(pipe(fds), -1, "pipe() failed"); + ASSERT_NE_MSG(write(fds[1], s, sizeof(s)), -1, "write() failed"); + errno = 0; + char buf[100]; + ssize_t return_code = ft_read(fds[0], buf, sizeof(s)); + ASSERT_GE(return_code, 0); + ASSERT_EQ((size_t)return_code, sizeof(s)); + ASSERT_EQ(errno, 0); + ASSERT_STREQ(s, buf); } UTEST(ft_read, long_string_partial) { - char s[] = "This is a long string with a lot of characters"; - int fds[2]; - ASSERT_NE_MSG(pipe(fds), -1, "pipe() failed"); - ASSERT_NE_MSG(write(fds[1], s, sizeof(s)), -1, "write() failed"); - errno = 0; - char buf[100]; - ssize_t return_code = ft_read(fds[0], buf, sizeof(s) - 1); - ASSERT_GE(return_code, 0); - ASSERT_EQ((size_t)return_code, sizeof(s) - 1); - ASSERT_EQ(errno, 0); - buf[sizeof(s) - 1] = '\0'; - ASSERT_STREQ(s, buf); + char s[] = "This is a long string with a lot of characters"; + int fds[2]; + ASSERT_NE_MSG(pipe(fds), -1, "pipe() failed"); + ASSERT_NE_MSG(write(fds[1], s, sizeof(s)), -1, "write() failed"); + errno = 0; + char buf[100]; + ssize_t return_code = ft_read(fds[0], buf, sizeof(s) - 1); + ASSERT_GE(return_code, 0); + ASSERT_EQ((size_t)return_code, sizeof(s) - 1); + ASSERT_EQ(errno, 0); + buf[sizeof(s) - 1] = '\0'; + ASSERT_STREQ(s, buf); } UTEST(ft_read, invalid_fd) { - char buf[100]; - errno = 0; - ssize_t return_code = ft_read(-1, buf, sizeof(buf)); - ASSERT_EQ(return_code, -1); - ASSERT_EQ(errno, EBADF); + char buf[100]; + errno = 0; + ssize_t return_code = ft_read(-1, buf, sizeof(buf)); + ASSERT_EQ(return_code, -1); + ASSERT_EQ(errno, EBADF); } UTEST(ft_read, close_fd) { - int fds[2]; - ASSERT_NE_MSG(pipe(fds), -1, "pipe() failed"); - ASSERT_NE_MSG(close(fds[0]), -1, "close() failed"); - errno = 0; - char buf[100]; - ssize_t return_code = ft_read(fds[0], buf, sizeof(buf)); - ASSERT_EQ(return_code, -1); - ASSERT_EQ(errno, EBADF); + int fds[2]; + ASSERT_NE_MSG(pipe(fds), -1, "pipe() failed"); + ASSERT_NE_MSG(close(fds[0]), -1, "close() failed"); + errno = 0; + char buf[100]; + ssize_t return_code = ft_read(fds[0], buf, sizeof(buf)); + ASSERT_EQ(return_code, -1); + ASSERT_EQ(errno, EBADF); } UTEST(ft_read, invalid_buf_with_EOF) { - int fds[2]; - ASSERT_NE_MSG(pipe(fds), -1, "pipe() failed"); - errno = 0; - ASSERT_NE_MSG(close(fds[1]), -1, "close() failed"); - ssize_t return_code = ft_read(fds[0], NULL, 100); - ASSERT_EQ(return_code, 0); - ASSERT_EQ(errno, 0); + int fds[2]; + ASSERT_NE_MSG(pipe(fds), -1, "pipe() failed"); + errno = 0; + ASSERT_NE_MSG(close(fds[1]), -1, "close() failed"); + ssize_t return_code = ft_read(fds[0], NULL, 100); + ASSERT_EQ(return_code, 0); + ASSERT_EQ(errno, 0); } UTEST(ft_read, invalid_buf) { - int fds[2]; - ASSERT_NE_MSG(pipe(fds), -1, "pipe() failed"); - errno = 0; - ASSERT_NE_MSG(write(fds[1], "1", 1), -1, "write() failed"); - ASSERT_NE_MSG(close(fds[1]), -1, "close() failed"); - ssize_t return_code = ft_read(fds[0], NULL, 100); - ASSERT_EQ(return_code, -1); - ASSERT_EQ(errno, EFAULT); + int fds[2]; + ASSERT_NE_MSG(pipe(fds), -1, "pipe() failed"); + errno = 0; + ASSERT_NE_MSG(write(fds[1], "1", 1), -1, "write() failed"); + ASSERT_NE_MSG(close(fds[1]), -1, "close() failed"); + ssize_t return_code = ft_read(fds[0], NULL, 100); + ASSERT_EQ(return_code, -1); + ASSERT_EQ(errno, EFAULT); } diff --git a/test/ft_strcmp.c b/test/ft_strcmp.c index f4ccb7a..252cb6f 100644 --- a/test/ft_strcmp.c +++ b/test/ft_strcmp.c @@ -12,69 +12,69 @@ #include -#include "utest.h" #include "libasm.h" +#include "utest.h" -static int32_t normalized_strcmp(const char *s1, const char *s2); +static int32_t normalized_strcmp(const char *s1, const char *s2); static int32_t normalized_ft_strcmp(const char *s1, const char *s2); static int32_t normalize_cmp(int32_t strcmp_return); UTEST(ft_strcmp, empty_string) { - char s1[] = ""; - char s2[] = ""; - ASSERT_EQ(normalized_ft_strcmp(s1, s2), normalized_strcmp(s1, s2)); - ASSERT_EQ(normalized_ft_strcmp(s2, s1), normalized_strcmp(s2, s1)); + char s1[] = ""; + char s2[] = ""; + ASSERT_EQ(normalized_ft_strcmp(s1, s2), normalized_strcmp(s1, s2)); + ASSERT_EQ(normalized_ft_strcmp(s2, s1), normalized_strcmp(s2, s1)); } UTEST(ft_strcmp, upper_string) { - char s1[] = "SOMETHING"; - char s2[] = "something"; - ASSERT_EQ(normalized_ft_strcmp(s1, s2), normalized_strcmp(s1, s2)); - ASSERT_EQ(normalized_ft_strcmp(s2, s1), normalized_strcmp(s2, s1)); + char s1[] = "SOMETHING"; + char s2[] = "something"; + ASSERT_EQ(normalized_ft_strcmp(s1, s2), normalized_strcmp(s1, s2)); + ASSERT_EQ(normalized_ft_strcmp(s2, s1), normalized_strcmp(s2, s1)); } UTEST(ft_strcmp, even_string) { - char s1[] = "SOMETHING1"; - char s2[] = "something1"; - ASSERT_EQ(normalized_ft_strcmp(s1, s2), normalized_strcmp(s1, s2)); - ASSERT_EQ(normalized_ft_strcmp(s2, s1), normalized_strcmp(s2, s1)); + char s1[] = "SOMETHING1"; + char s2[] = "something1"; + ASSERT_EQ(normalized_ft_strcmp(s1, s2), normalized_strcmp(s1, s2)); + ASSERT_EQ(normalized_ft_strcmp(s2, s1), normalized_strcmp(s2, s1)); } UTEST(ft_strcmp, simple_string) { - char s1[] = "1"; - char s2[] = "2"; - ASSERT_EQ(normalized_ft_strcmp(s1, s2), normalized_strcmp(s1, s2)); - ASSERT_EQ(normalized_ft_strcmp(s2, s1), normalized_strcmp(s2, s1)); + char s1[] = "1"; + char s2[] = "2"; + ASSERT_EQ(normalized_ft_strcmp(s1, s2), normalized_strcmp(s1, s2)); + ASSERT_EQ(normalized_ft_strcmp(s2, s1), normalized_strcmp(s2, s1)); } UTEST(ft_strcmp, long_string) { - char s1[] = "This is a long string with a lot of characters"; - char s2[] = "This is a long string with a lot of characters"; - ASSERT_EQ(normalized_ft_strcmp(s1, s2), normalized_strcmp(s1, s2)); - ASSERT_EQ(normalized_ft_strcmp(s2, s1), normalized_strcmp(s2, s1)); + char s1[] = "This is a long string with a lot of characters"; + char s2[] = "This is a long string with a lot of characters"; + ASSERT_EQ(normalized_ft_strcmp(s1, s2), normalized_strcmp(s1, s2)); + ASSERT_EQ(normalized_ft_strcmp(s2, s1), normalized_strcmp(s2, s1)); } UTEST(ft_strcmp, long_string_diff) { - char s1[] = "This is a long string with a lot of characters"; - char s2[] = "This is a long string with a lot of characters!"; - ASSERT_EQ(normalized_ft_strcmp(s1, s2), normalized_strcmp(s1, s2)); - ASSERT_EQ(normalized_ft_strcmp(s2, s1), normalized_strcmp(s2, s1)); + char s1[] = "This is a long string with a lot of characters"; + char s2[] = "This is a long string with a lot of characters!"; + ASSERT_EQ(normalized_ft_strcmp(s1, s2), normalized_strcmp(s1, s2)); + ASSERT_EQ(normalized_ft_strcmp(s2, s1), normalized_strcmp(s2, s1)); } -static int32_t normalized_strcmp(const char *s1, const char *s2) { - return (normalize_cmp(strcmp(s1, s2))); +static int32_t normalized_strcmp(const char *s1, const char *s2) { + return (normalize_cmp(strcmp(s1, s2))); } static int32_t normalized_ft_strcmp(const char *s1, const char *s2) { - return (normalize_cmp(ft_strcmp(s1, s2))); + return (normalize_cmp(ft_strcmp(s1, s2))); } static int32_t normalize_cmp(int32_t strcmp_return) { - if (strcmp_return < 0) { - return -1; - } else if (strcmp_return > 0) { - return 1; - } else { - return 0; - } + if (strcmp_return < 0) { + return -1; + } else if (strcmp_return > 0) { + return 1; + } else { + return 0; + } } diff --git a/test/ft_strcpy.c b/test/ft_strcpy.c index 4c0ef5d..f9ac0af 100644 --- a/test/ft_strcpy.c +++ b/test/ft_strcpy.c @@ -12,51 +12,50 @@ #include -#include "utest.h" #include "libasm.h" +#include "utest.h" UTEST(ft_strcpy, empty_string) { - char s1[] = ""; - char s2[100]; - char s3[100]; - ASSERT_EQ(ft_strcpy(s2, s1), s2); - ASSERT_EQ(strcpy(s3, s1), s3); - ASSERT_STREQ(s1, s3); + char s1[] = ""; + char s2[100]; + char s3[100]; + ASSERT_EQ(ft_strcpy(s2, s1), s2); + ASSERT_EQ(strcpy(s3, s1), s3); + ASSERT_STREQ(s1, s3); } UTEST(ft_strcpy, simple_string) { - char s1[] = "1"; - char s2[100]; - char s3[100]; - ASSERT_EQ(ft_strcpy(s2, s1), s2); - ASSERT_EQ(strcpy(s3, s1), s3); - ASSERT_STREQ(s1, s3); + char s1[] = "1"; + char s2[100]; + char s3[100]; + ASSERT_EQ(ft_strcpy(s2, s1), s2); + ASSERT_EQ(strcpy(s3, s1), s3); + ASSERT_STREQ(s1, s3); } UTEST(ft_strcpy, odd_string) { - char s1[] = "something"; - char s2[100]; - char s3[100]; - ASSERT_EQ(ft_strcpy(s2, s1), s2); - ASSERT_EQ(strcpy(s3, s1), s3); - ASSERT_STREQ(s1, s3); + char s1[] = "something"; + char s2[100]; + char s3[100]; + ASSERT_EQ(ft_strcpy(s2, s1), s2); + ASSERT_EQ(strcpy(s3, s1), s3); + ASSERT_STREQ(s1, s3); } UTEST(ft_strcpy, even_string) { - char s1[] = "something1"; - char s2[100]; - char s3[100]; - ASSERT_EQ(ft_strcpy(s2, s1), s2); - ASSERT_EQ(strcpy(s3, s1), s3); - ASSERT_STREQ(s1, s3); + char s1[] = "something1"; + char s2[100]; + char s3[100]; + ASSERT_EQ(ft_strcpy(s2, s1), s2); + ASSERT_EQ(strcpy(s3, s1), s3); + ASSERT_STREQ(s1, s3); } UTEST(ft_strcpy, long_string) { - char s1[] = "This is a long string with a lot of characters"; - char s2[100]; - char s3[100]; - ASSERT_EQ(ft_strcpy(s2, s1), s2); - ASSERT_EQ(strcpy(s3, s1), s3); - ASSERT_STREQ(s1, s3); + char s1[] = "This is a long string with a lot of characters"; + char s2[100]; + char s3[100]; + ASSERT_EQ(ft_strcpy(s2, s1), s2); + ASSERT_EQ(strcpy(s3, s1), s3); + ASSERT_STREQ(s1, s3); } - diff --git a/test/ft_strdup.c b/test/ft_strdup.c index 186c39c..3c9158b 100644 --- a/test/ft_strdup.c +++ b/test/ft_strdup.c @@ -12,42 +12,40 @@ #include -#include "utest.h" #include "libasm.h" +#include "utest.h" UTEST(ft_strdup, empty_string) { - char s1[] = ""; - char *s2 = ft_strdup(s1); - ASSERT_STREQ(s1, s2); - free(s2); + char s1[] = ""; + char *s2 = ft_strdup(s1); + ASSERT_STREQ(s1, s2); + free(s2); } UTEST(ft_strdup, simple_string) { - char s1[] = "1"; - char *s2 = ft_strdup(s1); - ASSERT_STREQ(s1, s2); - free(s2); + char s1[] = "1"; + char *s2 = ft_strdup(s1); + ASSERT_STREQ(s1, s2); + free(s2); } UTEST(ft_strdup, odd_string) { - char s1[] = "something"; - char *s2 = ft_strdup(s1); - ASSERT_STREQ(s1, s2); - free(s2); + char s1[] = "something"; + char *s2 = ft_strdup(s1); + ASSERT_STREQ(s1, s2); + free(s2); } UTEST(ft_strdup, even_string) { - char s1[] = "something1"; - char *s2 = ft_strdup(s1); - ASSERT_STREQ(s1, s2); - free(s2); + char s1[] = "something1"; + char *s2 = ft_strdup(s1); + ASSERT_STREQ(s1, s2); + free(s2); } UTEST(ft_strdup, long_string) { - char s1[] = "This is a long string with a lot of characters"; - char *s2 = ft_strdup(s1); - ASSERT_STREQ(s1, s2); - free(s2); + char s1[] = "This is a long string with a lot of characters"; + char *s2 = ft_strdup(s1); + ASSERT_STREQ(s1, s2); + free(s2); } - - diff --git a/test/ft_strlen.c b/test/ft_strlen.c index 00b2075..872852d 100644 --- a/test/ft_strlen.c +++ b/test/ft_strlen.c @@ -12,25 +12,25 @@ #include -#include "utest.h" #include "libasm.h" +#include "utest.h" UTEST(ft_strlen, empty_string) { - char string[] = ""; - ASSERT_EQ(ft_strlen(string), strlen(string)); + char string[] = ""; + ASSERT_EQ(ft_strlen(string), strlen(string)); } UTEST(ft_strlen, odd_string) { - char string[] = "something"; - ASSERT_EQ(ft_strlen(string), strlen(string)); + char string[] = "something"; + ASSERT_EQ(ft_strlen(string), strlen(string)); } UTEST(ft_strlen, even_string) { - char string[] = "something1"; - ASSERT_EQ(ft_strlen(string), strlen(string)); + char string[] = "something1"; + ASSERT_EQ(ft_strlen(string), strlen(string)); } UTEST(ft_strlen, simple_string) { - char string[] = "1"; - ASSERT_EQ(ft_strlen(string), strlen(string)); + char string[] = "1"; + ASSERT_EQ(ft_strlen(string), strlen(string)); } diff --git a/test/ft_write.c b/test/ft_write.c index 584fdda..4974fa6 100644 --- a/test/ft_write.c +++ b/test/ft_write.c @@ -10,104 +10,104 @@ /* */ /* ************************************************************************** */ -#include "utest.h" #include "libasm.h" +#include "utest.h" UTEST(ft_write, empty_string) { - char s[] = ""; - int fds[2]; - ASSERT_NE_MSG(pipe(fds), -1, "pipe() failed"); - errno = 0; - ssize_t return_code = ft_write(fds[1], s, sizeof(s)); - char buf[100]; - ASSERT_NE_MSG(read(fds[0], buf, sizeof(s)), -1, "read() failed"); - ASSERT_GE(return_code, 0); - ASSERT_EQ((size_t)return_code, sizeof(s)); - ASSERT_EQ(errno, 0); - ASSERT_STREQ(s, buf); + char s[] = ""; + int fds[2]; + ASSERT_NE_MSG(pipe(fds), -1, "pipe() failed"); + errno = 0; + ssize_t return_code = ft_write(fds[1], s, sizeof(s)); + char buf[100]; + ASSERT_NE_MSG(read(fds[0], buf, sizeof(s)), -1, "read() failed"); + ASSERT_GE(return_code, 0); + ASSERT_EQ((size_t)return_code, sizeof(s)); + ASSERT_EQ(errno, 0); + ASSERT_STREQ(s, buf); } UTEST(ft_write, simple_string) { - char s[] = "1"; - int fds[2]; - ASSERT_NE_MSG(pipe(fds), -1, "pipe() failed"); - errno = 0; - ssize_t return_code = ft_write(fds[1], s, sizeof(s)); - char buf[100]; - ASSERT_NE_MSG(read(fds[0], buf, sizeof(s)), -1, "read() failed"); - ASSERT_GE(return_code, 0); - ASSERT_EQ((size_t)return_code, sizeof(s)); - ASSERT_EQ(errno, 0); - ASSERT_STREQ(s, buf); + char s[] = "1"; + int fds[2]; + ASSERT_NE_MSG(pipe(fds), -1, "pipe() failed"); + errno = 0; + ssize_t return_code = ft_write(fds[1], s, sizeof(s)); + char buf[100]; + ASSERT_NE_MSG(read(fds[0], buf, sizeof(s)), -1, "read() failed"); + ASSERT_GE(return_code, 0); + ASSERT_EQ((size_t)return_code, sizeof(s)); + ASSERT_EQ(errno, 0); + ASSERT_STREQ(s, buf); } UTEST(ft_write, odd_string) { - char s[] = "something"; - int fds[2]; - ASSERT_NE_MSG(pipe(fds), -1, "pipe() failed"); - errno = 0; - ssize_t return_code = ft_write(fds[1], s, sizeof(s)); - char buf[100]; - ASSERT_NE_MSG(read(fds[0], buf, sizeof(s)), -1, "read() failed"); - ASSERT_GE(return_code, 0); - ASSERT_EQ((size_t)return_code, sizeof(s)); - ASSERT_EQ(errno, 0); - ASSERT_STREQ(s, buf); + char s[] = "something"; + int fds[2]; + ASSERT_NE_MSG(pipe(fds), -1, "pipe() failed"); + errno = 0; + ssize_t return_code = ft_write(fds[1], s, sizeof(s)); + char buf[100]; + ASSERT_NE_MSG(read(fds[0], buf, sizeof(s)), -1, "read() failed"); + ASSERT_GE(return_code, 0); + ASSERT_EQ((size_t)return_code, sizeof(s)); + ASSERT_EQ(errno, 0); + ASSERT_STREQ(s, buf); } UTEST(ft_write, even_string) { - char s[] = "something1"; - int fds[2]; - ASSERT_NE_MSG(pipe(fds), -1, "pipe() failed"); - errno = 0; - ssize_t return_code = ft_write(fds[1], s, sizeof(s)); - char buf[100]; - ASSERT_NE_MSG(read(fds[0], buf, sizeof(s)), -1, "read() failed"); - ASSERT_GE(return_code, 0); - ASSERT_EQ((size_t)return_code, sizeof(s)); - ASSERT_EQ(errno, 0); - ASSERT_STREQ(s, buf); + char s[] = "something1"; + int fds[2]; + ASSERT_NE_MSG(pipe(fds), -1, "pipe() failed"); + errno = 0; + ssize_t return_code = ft_write(fds[1], s, sizeof(s)); + char buf[100]; + ASSERT_NE_MSG(read(fds[0], buf, sizeof(s)), -1, "read() failed"); + ASSERT_GE(return_code, 0); + ASSERT_EQ((size_t)return_code, sizeof(s)); + ASSERT_EQ(errno, 0); + ASSERT_STREQ(s, buf); } UTEST(ft_write, long_string) { - char s[] = "This is a long string with a lot of characters"; - int fds[2]; - ASSERT_NE_MSG(pipe(fds), -1, "pipe() failed"); - errno = 0; - ssize_t return_code = ft_write(fds[1], s, sizeof(s)); - char buf[100]; - ASSERT_NE_MSG(read(fds[0], buf, sizeof(s)), -1, "read() failed"); - ASSERT_GE(return_code, 0); - ASSERT_EQ((size_t)return_code, sizeof(s)); - ASSERT_EQ(errno, 0); - ASSERT_STREQ(s, buf); + char s[] = "This is a long string with a lot of characters"; + int fds[2]; + ASSERT_NE_MSG(pipe(fds), -1, "pipe() failed"); + errno = 0; + ssize_t return_code = ft_write(fds[1], s, sizeof(s)); + char buf[100]; + ASSERT_NE_MSG(read(fds[0], buf, sizeof(s)), -1, "read() failed"); + ASSERT_GE(return_code, 0); + ASSERT_EQ((size_t)return_code, sizeof(s)); + ASSERT_EQ(errno, 0); + ASSERT_STREQ(s, buf); } UTEST(ft_write, invalid_fd) { - char s[] = "This is a long string with a lot of characters"; - errno = 0; - ssize_t return_code = ft_write(-1, s, sizeof(s)); - ASSERT_EQ(return_code, -1); - ASSERT_EQ(errno, EBADF); + char s[] = "This is a long string with a lot of characters"; + errno = 0; + ssize_t return_code = ft_write(-1, s, sizeof(s)); + ASSERT_EQ(return_code, -1); + ASSERT_EQ(errno, EBADF); } UTEST(ft_write, close_fd) { - char s[] = "This is a long string with a lot of characters"; - int fds[2]; - ASSERT_NE_MSG(pipe(fds), -1, "pipe() failed"); - ASSERT_NE_MSG(close(fds[1]), -1, "close() failed"); - errno = 0; - ssize_t return_code = ft_write(fds[1], s, sizeof(s)); - ASSERT_EQ(return_code, -1); - ASSERT_EQ(errno, EBADF); + char s[] = "This is a long string with a lot of characters"; + int fds[2]; + ASSERT_NE_MSG(pipe(fds), -1, "pipe() failed"); + ASSERT_NE_MSG(close(fds[1]), -1, "close() failed"); + errno = 0; + ssize_t return_code = ft_write(fds[1], s, sizeof(s)); + ASSERT_EQ(return_code, -1); + ASSERT_EQ(errno, EBADF); } UTEST(ft_write, invalid_buf) { - char s[] = "This is a long string with a lot of characters"; - int fds[2]; - ASSERT_NE_MSG(pipe(fds), -1, "pipe() failed"); - errno = 0; - ssize_t return_code = ft_write(fds[1], NULL, sizeof(s)); - ASSERT_EQ(return_code, -1); - ASSERT_EQ(errno, EFAULT); + char s[] = "This is a long string with a lot of characters"; + int fds[2]; + ASSERT_NE_MSG(pipe(fds), -1, "pipe() failed"); + errno = 0; + ssize_t return_code = ft_write(fds[1], NULL, sizeof(s)); + ASSERT_EQ(return_code, -1); + ASSERT_EQ(errno, EFAULT); }