Skip to content
This repository was archived by the owner on Aug 19, 2019. It is now read-only.

Base64 unit tests#71

Merged
igorpeshansky merged 9 commits intomasterfrom
ACEmilG-base64-unit-tests
Mar 13, 2018
Merged

Base64 unit tests#71
igorpeshansky merged 9 commits intomasterfrom
ACEmilG-base64-unit-tests

Conversation

@ACEmilG
Copy link
Copy Markdown
Contributor

@ACEmilG ACEmilG commented Mar 9, 2018

Add testing for base64 encoding. Remove base64 decoding from header file to reflect its commented out implementation.

Copy link
Copy Markdown
Contributor

@igorpeshansky igorpeshansky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Please try to apply each comment everywhere it makes sense.

Comment thread src/base64.h Outdated
std::string Encode(const std::string &source);

std::string Decode(const std::string &source);
//std::string Decode(const std::string &source);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you decide to comment this out?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The definition is commented out, so I thought I would reflect that in the header file. It seemed wrong to have a declaration with no definition anywhere.

I don't feel tied to this - happy to change it back.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's uncomment this. To be honest, I've also uncommented the implementation and tested it in my private clone, and it works fine, so we might as well make it available, even if we don't yet use it.
Want me to push the commit that does that?

Comment thread test/Makefile Outdated
TEST_OBJS=$(TEST_SOURCES:$(TEST_DIR)/%.cc=%.o)
TESTS=\
format_unittest
format_unittest\
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a space before the \.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread test/base64_unittest.cc Outdated
namespace {

TEST(EncodeTest, EmptyEncode) {
const std::string empty_str("");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May not be worth naming the constants... How about just inlining them into the EXPECT_EQ? I.e.,

TEST (EncodeTest, EmptyEncode) {
  EXPECT_EQ("", base64::Encode(""));
}

?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed - done.

Comment thread test/base64_unittest.cc Outdated
);
}

TEST(EncodeTest, NoPaddingEncode) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to add a comment explaining the "no padding" bit? E.g., // 5 bytes should produce 7 characters.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, done.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been trying to come up with a good name for the "padding" tests... The best I got so far is "phantom" (as in "phantom characters at the end"). So this test would have been named "OnePhantom", and the double padding one below would become "TwoPhantoms". WDYT? Happy to hear suggestions for better names. Ultimately, I think we ought to explain what we're testing in a comment if the test name isn't sufficiently expressive.
Your comment explains "no padding", but not the difference between the single and double pad characters.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Phantom sounds good to me. Hopefully the new comment is more clear.

Comment thread test/base64_unittest.cc Outdated
);
}

TEST(EncodeTest, NoDoublePaddingEncode) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why "double padding"? Can you please elaborate?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure: Typically this would have "==" as padding, hence the "double" as opposed to the above which would have "=" (single). I guess its kind of a trivial case, happy to remove it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's an important corner case and needs to be tested, but see my other note about test naming.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed above.

Comment thread src/base64.h Outdated
std::string Encode(const std::string &source);

std::string Decode(const std::string &source);
//std::string Decode(const std::string &source);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's uncomment this. To be honest, I've also uncommented the implementation and tested it in my private clone, and it works fine, so we might as well make it available, even if we don't yet use it.
Want me to push the commit that does that?

Comment thread test/base64_unittest.cc Outdated
namespace {

TEST(EncodeTest, EmptyEncode) {
EXPECT_EQ(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's save some vertical space and put this whole EXPECT_EQ on a single line. Ditto below.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, fixed.

Comment thread test/base64_unittest.cc Outdated
);
}

//Base64 encodings typically pad messages to ensure output length % 4 == 0, our
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: missing space after comment marker.

Comment thread test/base64_unittest.cc Outdated
}

//Base64 encodings typically pad messages to ensure output length % 4 == 0, our
//implementation does not
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: missing trailing ".".

Comment thread test/base64_unittest.cc Outdated
);
}

TEST(EncodeTest, NoPaddingEncode) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been trying to come up with a good name for the "padding" tests... The best I got so far is "phantom" (as in "phantom characters at the end"). So this test would have been named "OnePhantom", and the double padding one below would become "TwoPhantoms". WDYT? Happy to hear suggestions for better names. Ultimately, I think we ought to explain what we're testing in a comment if the test name isn't sufficiently expressive.
Your comment explains "no padding", but not the difference between the single and double pad characters.

Comment thread test/base64_unittest.cc Outdated
);
}

TEST(EncodeTest, NoDoublePaddingEncode) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's an important corner case and needs to be tested, but see my other note about test naming.

Comment thread test/base64_unittest.cc Outdated
}

// Base64 encoders typically pad messages to ensure output length % 4 == 0. To
// acheive this, encoders will pad messages with either one or two "=". Our
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's stick to one space after "." (throughout).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Copy link
Copy Markdown
Contributor

@igorpeshansky igorpeshansky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM :shipit:

Copy link
Copy Markdown
Contributor

@supriyagarg supriyagarg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A very minor comment., otherwise LGTM.

Comment thread test/base64_unittest.cc Outdated
}

// Base64 encoders typically pad messages to ensure output length % 4 == 0. To
// acheive this, encoders will pad messages with either one or two "=". Our
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

acheive -> achieve

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Copy link
Copy Markdown
Contributor

@igorpeshansky igorpeshansky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM :shipit: again.

@igorpeshansky igorpeshansky merged commit 39932b0 into master Mar 13, 2018
@igorpeshansky igorpeshansky deleted the ACEmilG-base64-unit-tests branch March 13, 2018 12:52
igorpeshansky pushed a commit that referenced this pull request Mar 13, 2018
Also fix bug in alternate base64::Encode implementation and enable base64::Decode.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants